NEW
Font size
WorksheetsPolymorphism & Exception Handling in Java
Total questions: 53
Worksheet time: 33mins
What is the output of this program?
0
1
2
Compilation Error
What is the output of this program?
2 2
3 3
2 3
3 2
What is the output of this program?
1 2
2 1
Runtime Error
Compilation Error
what is the output?
Base
Derived
compile time error
run-time error
Output of following Java program?
Base
Derived
Derived
Base
Base
Derived
Base
Derived
Base
Compiler Error
Which of the following is true about inheritance in Java?
1, 2 and 4
Only 1 and 2
1, 2 and 3
2, 3 and 4
output of the program
Base::show() called
Compiler Error
Derived::show() called
None
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?
0
garbage value
compile time error
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
Predict the output of the following program.
Compilation error
Inside First
Inside First
Inside First
Inside Second
Runtime error
What is the output of the following JAVA program ?
dogood : dogoodgood
dogood : gooddogood
dogood : dodogood
dogood : dogood
Predict the output?
20
0
Compiler Error
none
Which of the following is/are true about constructors in Java?
1
1,2
1, 2, 4
1,2,3 & 4
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 process of defining a method in a subclass having same name & type signature as a method in its superclass?
Method overloading
Method overriding
Method hiding
None of the mentioned
What is the output of this program?
2
3
7
compile time error
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
Determine the output?
r1 r4 pre b1 b2 post
pre r1 r4 b1 b2 r2 r3 post
r1 r4 pre b1 b2 r3 r2 post
r1 r4 pre b1 b2 post r3 r2
Determine the output?
one
one two
one two 20
20
one 20
Read the statement
Declare the method with the keyword public.
Declare the method with the keyword private.
Declare the method with the keyword protected.
Do not declare the method with any accessibility modifiers.
Declare the method with the keyword public and private.
Read the statement
Only (III)
(II) and (III)
(I) and (II)
Only (I)
(I), (II) and (III)
Read the Program
1 and 2
2 and 4
3 and 4
1 and 3
A Package is the collection of
classes
interfaces
classes and interfaces
editing tools
editing tools and interfaces
which of these lines will give compile time error?
1
2
3
4
None of these
The class at the top of the exception hierarchy is
ArithmeticException
Throwable
Object
Exception
in which package Exception class is available?
java.util
java.file
java.io
java.lang
java.net
Exception generated in try block will caught in...... block
catch
throw
throws
finally
which keyword is used to explicitly throw an exception?
try
throwing
catch
throw
throws
which exception will through by decided by zero?
NumberFormatException
ArithmeticException
NullPointerException
None of these
What happen in case of multiple catch blocks
Either super or subclass can be caught first.
The superclass exception must be caught first.
The superclass exception cannot caught first.
None of these
What will be the output?
inCatchBlock
inCatchBlock inFinallyBlock
inFinallyBlock
The program will return without printing anything
Given the following piece of code
1 and 4
2 and 3
2 and 4
3 and 4
1 and 2
what is the output?
There is a NullPointerException.
There is a NullPointerException. Everything went fine.
There is a NullPointerException. There is an Exception.
This code will not compile, because in Java there are no pointers.
what is the output?
One
Two
One Two
Compilation Error
Read the statement
A and D
A and B
A and C
B and C
What is the output?
"doCdoBdoA" is printed
"doAdoBdoC" is printed
"doBdoAerror" is printed
"error" is printed
nothing is printed
what will be the result if NullPointerException occurs at line 2.
1
3
2 3
1 3
1 2 3
What is the output?
"one" is printed.
"null pointer exception" is printed.
"exception" is printed.
Compilation fails saying NullPointerException has already been caught.
None of these
what is the output after compilation of this code?
Overridden: hello (String, Integer[])
Compilation fails
hello (String, Integer[])
None of these
Is this program create a new file with a.txt
true
false
None of these
Compilation Error
what is the output?
Value-A
Compilation fails-Exception NullPointerException is not compatible with throws clause in A.printName()
Name-B
Compilation succeed but no output
None of these
What is the output of this program?
Prints out: Exception
Prints out: Exception Finally
Compile with error
Prints out: Finally
None of these
What is the output?
3
3.5
Compilation Error
None of these
what exception could be handled by catch block
IllegalStateException
ClassCastException
NumberFormatException
ArrayIndexOutOfBoundsException
None of these
What is the output?
Got the Exception 10
Got the Exception 0
Compiler Error
none of the above
What is the output?
Got the Test Exception
Inside finally block
Got the Test Exception
Inside finally block
Compiler Error
What is the output?
Caught base class exception
Caught derived class exception
Compiler Error because derived is not throwable
Compiler Error because base class exception is caught before derived class
What is the output?
Compile error
Divide by zero error
a = 0
Divide by zero error
inside the finally block
a = 0
inside the finally block
What is the output?
error occurred
End of the program
Not Eligible for voting
End of the program
Eligible for voting
End of the program
none
