Font size
WorksheetsException Handling Package Interface Test
Total questions: 81
Worksheet time: 3hrs 42mins
What is the advantage of Exception Handling
To avoid abnormal termination of a program
To find out errors
To Debug program
None of these
Which of the following key word is optional in Exception handling program
try
catch
finally
throw
try block may or may not contains catch blocks
True
False
What is the purpose of 'throw' keyword
To Raise an exception explicityly
To Raise an exception implicityly
To create user defined exceptions
To create custom exceptions
What is an exception
Error occurred during the execution of a program
Bug occurred during the compile time of a program
Simply an Error
It is related to input values
Exception classes belongs to following package
import java.io.*
import java.lang.*
import java.util.*
import java.lang.Exception.*
Which of these keywords is not a part of exception handling?
try
finally
thrown
catch
Which of these class is highest in hierarchy in java
java.lang.Exception
java.lang.Error
java.lang.Throwable
java.lang.Object
Choose the CORRECT exception
String department="JTMK";
Integer no=Integer.parseInt(department);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundsException
1. Which of these keywords must be used to monitor for exceptions?
a) try
b) finally
c) throw
d) catch
2. Class at the top of exception class hierarchy?
ArithmeticException
Throwable
Object
Exception
3. In which of the following package, Exception class exist?
java.util
java.io
java.lang
java.file
4. Exception generated by try block is caught in ______ block?
catch
throw
throws
finally
Exception and Error are direct subclasses of?
.BaseException
Throwable
Object
RuntimeException
What block is always executed, independently of a exception being raised?
throws
finally
catch
throw
What keyword is used to explicitly raise a exception?
catch
throw
throws
raise
Exception is a class/interface/abstract class/other?
Class
Interface
Abstract class
Other
What type of exception is thrown by parseInt() if it gets illegal data?
ArithmeticException
RunTimeException
NumberFormatException
NumberErro
Which option is correct for creating a package named s3cs ?
create package s3cs;
package s3cs;
define package 3cs;
s3cs;
To use a class or a package from the library which keyword is used
include
package
import
export
A class member can be accessed only by a class in the same package. Which is the suitable access specifier?
public
default
private
protected
A class member cannot be accessed by any other class inside or outside the package. Which is the suitable access specifier?
private
public
default
protected
Which of the following help to access all the classes in the package p1?
import p1;
import p1.*;
import p1.all;
import p1.A;
Which of the following help to use class Sample from package adm? (choose all appropriate options)
import admSample;
import adm.Sample;
import Sample;
import adm.*;
Multiple inheritance in Java can be achieved using
class and interface
class
interface
package
Which of the following is true about interface?
Interface can contain abstract methods.
A class implementing an interface should define all the methods in that interface.
Interface is not used for creating objects.
All of the above
Choose the CORRECT mechanism of exception handling.
try block --> catch block --> finally block
try block --> catch block --> throws exception
try block --> catch block --> finally --> throws exception
try block --> throws exception--> catch block --> finally block
output of the program
Base::show() called
Derived::show() called
Compiler Error
Runtime Error
output of the program
Base::show() called
Derived::show() called
Compiler Error
Runtime Error
Output of following Java Program?
Derived::show() called
compile time error
Base::show() called
runtime error
Predict the output of following Java program
garbage value
0
compile time error
runtime error
output of the program
Compile error
values of obj1:
a = 11 b = 21
values of obj2:
a = 11 b = 21
values of obj1:
a = 11 b = 21
values of obj2:
a = 10 b = 20
values of obj1:
a = 11 b = 20
values of obj2:
a = 10 b = 21
runtime error
What is the output of the following JAVA program ?
dogood : dogoodgood
dogood : gooddogood
dogood : dodogood
dogood : dogood
output of the program
inside static block
a = 4
inside constructor
a = 11
Compiler Error
Run Time Error
inside static block
a = 4
inside constructor
a = 5
inside static block
a = 10
inside constructor
a = 11
what is the output
9.0 9.0
9 9
compile time error
none
I am a Person
I am a Student
I am a Person I am a Student
I am a Student I am a Person
Which of this access specifies can be used for a class so that its members can be accessed by a different class in the same package?
Public
Protected
No Modifier
All of the mentioned
Which of these access specifiers can be used for a class so that its members can be accessed by a different class in the different package?
Public
Protected
Private
No Modifier
Which of the following is an incorrect statement about packages?
Package defines a namespace in which classes are stored
A package can contain other package within it
Java uses file system directories to store packages
A package can be renamed without renaming the directory in which the classes are stored
For which purpose packages are used in Java?
Categorizes data
Organizing java classes into namespaces
faster compilation
None of These
which package is imported implicitly?
java.applet
java.util
java.lang
java.io
Math class is in ………package.
java.io
java.lang
java.util
java.applet
By convention, java packages begin with ………………. letters while all the class names begin with an ………………… letter.
uppercase, uppercase
lowercase, lowercase
uppercase, lowercase
lowercase, uppercase
A package is a collection of
classes
interfaces
editing tools
classes and interfaces
What are the valid statements for static keyword in Java?
We can have static block in a class.
The static block in a class is executed every time an object of class is created.
We can have static method implementations in interface.
We can define static block inside a method.
What is meaning * in import statement?
To import selected classes from a package
To import all classes from a package
To import all classes from a package and multiply it
It is compulsory to write main() function inside the class in Java.
True
False
What will be the output of the following Java program?
0
2
4
None of these
Which of these can be used to fully abstract a class from its implementation?
Objects
Packages
Interfaces
None of the Mentioned
What is the output of this program?
a=10
a=20
Compilation Error
No Error, but no output
What type of variable can be defined in an interface?
public static
private final
public final
static final
What does an interface contain?
Method definition
Method declaration
Method declaration and definition
Method name
Which of the following is correct way of implementing an interface salary by class manager?
class manager extends salary {}
class manager implements salary {}
class manager imports salary {}
None of the mentioned.
What will be the output of the following Java program?
0 1 2
0 2 4
0 0 4
0 1 4
Abstract class can have constructors and static methods?
TRUE
FALSE
Abstract class can have constructors but can not have static methods.
Abstract class can not have constructors but can have static methods.
Which of these is not a correct statement?
Every class containing abstract method must be declared abstract
Abstract class defines only the structure of the class not its implementation
Abstract class can be initiated by new operator
Abstract class can be inherited
The following Syntax is used for?
class Subclass-name extends Superclass-name
{
//methods and fields
}
Polymorphism
Encapsulation
Inheritance
None of the above
What is an abstract method?
An abstract method is any method in an abstract class.
An abstract method is a method which cannot be inherited.
An abstract method is one without a body that is declared with the reserved word abstract.
n abstract method is a method in the child class that overrids a parent method.
Predict the output :
ArrayIndexOutOfBoundsException
null
0
1
An interface extends a class
True
interface implements a class
Arithmetic Exception
Compiler Error
What will be the output?
Nothing
10
Compile time error
Runtime Exception
Inside an interface, every method is public and abstract.
TRUE
FALSE
The interface methods can be made final.
TRUE
FALSE
What is the output?
Compiler Error
Happy Holi
Run time Exception
No error, No output
The scope of an interface method implemented in a class (overridden) must be
always private
always less than the scope of interface method
always more than the scope of interface method
always public
Object creation for Interface and abstract class..
Cannot be created for both
Can be created for Interface
Can be created for Abstract class
Can be created for both
We prefer using interface when __________, and an abstract class when ______________.
classes are not required, interfaces are not required
we don't know any implementation, we know partial implementations
we know every implementation, we know partial implementation
we work on Java, we work on C++; It depends on language
10
0
5
12
0
5
10
5
0
12
0
5
25
24
32
33
0 2 4 6 8
1 2 3 4 5
0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
super keyword in Java is used for ?
to refer to immediate child class of a class.
to refer to current class object.
to refer to immediate parent class of a class.
to refer to static member of parent class.
Which is true ?
"X extends Y" is correct if X and Y are either both classes or both interface.
"X extends Y" is correct if and only if X is a interface and Y is a class.
"X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.
"X extends Y" is correct if and only if X is a class and Y is an interface.
If a class inheriting an abstract class does not define all of its function then it will be known as?
abstract
A simple class
Static class
None of the mentioned
Which of the statement is false about an abstract class ?
An abstract class is a class that contains one or more abstract methods.
An abstract class cannot have normal method.
An abstract class cannot be instantiated.
An abstract class can be extended.
Which of the following statement is true about an Interface ?
Interface can not be nested inside another interface.
Interface cannot implement a class.
Interface can not extend one or more other interface.
Methods inside Interface can be static, final, native or strictfp.
1,3 and 4
1,2 and 4
2,3 and 4
1,2,3 and 4
1 and 2 only
2,3 and 5
3,4 and 5
2 and 4
which of the following are not java keywords
double
switch
then
instance of
what is size of int in Java?
2 bytes
4 bytes
6 bytes
8 bytes
Import java.lang.*;
class Rectangle
{
int l,b,a;
a=l*b;
void fun()
{
l=10;
b=20;
system.out.println("Area = ", a);
}
}
Identify errors in above program segment.
Error in import line and Error in println line both
Error in import line
Error in println line
No error at all
To use a class or a package from the library which keyword is used
include
package
import
export
