wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Polymorphism & Exception Handling in Java

Total questions: 53

Worksheet time: 33mins

Name
Class
Date
1.

What is the output of this program?

a)

0

b)

1

c)

2

d)

Compilation Error

2.

What is the output of this program?

a)

2 2

b)

3 3

c)

2 3

d)

3 2

3.

What is the output of this program?

a)

1 2

b)

2 1

c)

Runtime Error

d)

Compilation Error

4.

what is the output?

a)

Base

b)

Derived

c)

compile time error

d)

run-time error

5.

Output of following Java program?

a)

Base

Derived

Derived

b)

Base

Base

Derived

c)

Base

Derived

Base

d)

Compiler Error

6.

Which of the following is true about inheritance in Java?

a)

1, 2 and 4

b)

Only 1 and 2

c)

1, 2 and 3

d)

2, 3 and 4

7.

output of the program

a)

Base::show() called

b)

Compiler Error

c)

Derived::show() called

d)

None

8.

output of the program

a)

Base::show() called

b)

Derived::show() called

c)

Compiler Error

d)

Runtime Error

9.

Output of following Java Program?

a)

Derived::show() called

b)

compile time error

c)

Base::show() called

d)

runtime error

10.

Predict the output of following Java program?

a)

0

b)

garbage value

c)

compile time error

d)

runtime error

11.

Predict the output of following Java program

a)

garbage value

b)

0

c)

compile time error

d)

runtime error

12.

output of the program

a)

Compile error

b)

values of obj1:

a = 11 b = 21

values of obj2:

a = 11 b = 21

c)

values of obj1:

a = 11 b = 21

values of obj2:

a = 10 b = 20

d)

values of obj1:

a = 11 b = 20

values of obj2:

a = 10 b = 21

e)

runtime error

13.

Predict the output of the following program.

a)

Compilation error

b)

Inside First

Inside First

c)

Inside First

Inside Second

d)

Runtime error

14.

What is the output of the following JAVA program ?

a)

dogood : dogoodgood

b)

dogood : gooddogood

c)

dogood : dodogood

d)

dogood : dogood

15.

Predict the output?

a)

20

b)

0

c)

Compiler Error

d)

none

16.

Which of the following is/are true about constructors in Java?

a)

1

b)

1,2

c)

1, 2, 4

d)

1,2,3 & 4

17.

output of the program

a)

inside static block

a = 4

inside constructor

a = 11

b)

Compiler Error

c)

Run Time Error

d)

inside static block

a = 4

inside constructor

a = 5

e)

inside static block

a = 10

inside constructor

a = 11

18.

What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?

a)

Method overloading

b)

Method overriding

c)

Method hiding

d)

None of the mentioned

19.

What is the output of this program?

a)

2

b)

3

c)

7

d)

compile time error

20.

what is the output

a)

9.0 9.0

b)

9 9

c)

compile time error

d)

none

21.
a)

I am a Person

b)

I am a Student

c)

I am a Person I am a Student

d)

I am a Student I am a Person

22.

Determine the output?

a)

r1 r4 pre b1 b2 post

b)

pre r1 r4 b1 b2 r2 r3 post

c)

r1 r4 pre b1 b2 r3 r2 post

d)

r1 r4 pre b1 b2 post r3 r2

23.

Determine the output?

a)

one

b)

one two

c)

one two 20

d)

20

e)

one 20

24.

Read the statement

a)

Declare the method with the keyword public.

b)

Declare the method with the keyword private.

c)

Declare the method with the keyword protected.

d)

Do not declare the method with any accessibility modifiers.

e)

Declare the method with the keyword public and private.

25.

Read the statement

a)

Only (III)

b)

(II) and (III)

c)

(I) and (II)

d)

Only (I)

e)

(I), (II) and (III)

26.

Read the Program

a)

1 and 2

b)

2 and 4

c)

3 and 4

d)

1 and 3

27.

A Package is the collection of

a)

classes

b)

interfaces

c)

classes and interfaces

d)

editing tools

e)

editing tools and interfaces

28.

which of these lines will give compile time error?

a)

1

b)

2

c)

3

d)

4

e)

None of these

29.

The class at the top of the exception hierarchy is

a)

ArithmeticException

b)

Throwable

c)

Object

d)

Exception

30.

in which package Exception class is available?

a)

java.util

b)

java.file

c)

java.io

d)

java.lang

e)

java.net

31.

Exception generated in try block will caught in...... block

a)

catch

b)

throw

c)

throws

d)

finally

32.

which keyword is used to explicitly throw an exception?

a)

try

b)

throwing

c)

catch

d)

throw

e)

throws

33.

which exception will through by decided by zero?

a)

NumberFormatException

b)

ArithmeticException

c)

NullPointerException

d)

None of these

34.

What happen in case of multiple catch blocks

a)

Either super or subclass can be caught first.

b)

The superclass exception must be caught first.

c)

The superclass exception cannot caught first.

d)

None of these

35.

What will be the output?

a)

inCatchBlock

b)

inCatchBlock inFinallyBlock

c)

inFinallyBlock

d)

The program will return without printing anything

36.

Given the following piece of code

a)

1 and 4

b)

2 and 3

c)

2 and 4

d)

3 and 4

e)

1 and 2

37.

what is the output?

a)

There is a NullPointerException.

b)

There is a NullPointerException. Everything went fine.

c)

There is a NullPointerException. There is an Exception.

d)

This code will not compile, because in Java there are no pointers.

38.

what is the output?

a)

One

b)

Two

c)

One Two

d)

Compilation Error

39.

Read the statement

a)

A and D

b)

A and B

c)

A and C

d)

B and C

40.

What is the output?

a)

"doCdoBdoA" is printed

b)

"doAdoBdoC" is printed

c)

"doBdoAerror" is printed

d)

"error" is printed

e)

nothing is printed

41.

what will be the result if NullPointerException occurs at line 2.

a)

1

b)

3

c)

2 3

d)

1 3

e)

1 2 3

42.

What is the output?

a)

"one" is printed.

b)

"null pointer exception" is printed.

c)

"exception" is printed.

d)

Compilation fails saying NullPointerException has already been caught.

e)

None of these

43.

what is the output after compilation of this code?

a)

Overridden: hello (String, Integer[])

b)

Compilation fails

c)

hello (String, Integer[])

d)

None of these

44.

Is this program create a new file with a.txt

a)

true

b)

false

c)

None of these

d)

Compilation Error

45.

what is the output?

a)

Value-A

b)

Compilation fails-Exception NullPointerException is not compatible with throws clause in A.printName()

c)

Name-B

d)

Compilation succeed but no output

e)

None of these

46.

What is the output of this program?

a)

Prints out: Exception

b)

Prints out: Exception Finally

c)

Compile with error

d)

Prints out: Finally

e)

None of these

47.

What is the output?

a)

3

b)

3.5

c)

Compilation Error

d)

None of these

48.

what exception could be handled by catch block

a)

IllegalStateException

b)

ClassCastException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundsException

e)

None of these

49.

What is the output?

a)

Got the Exception 10

b)

Got the Exception 0

c)

Compiler Error

d)

none of the above

50.

What is the output?

a)

Got the Test Exception

Inside finally block

b)

Got the Test Exception

c)

Inside finally block

d)

Compiler Error

51.

What is the output?

a)

Caught base class exception

b)

Caught derived class exception

c)

Compiler Error because derived is not throwable

d)

Compiler Error because base class exception is caught before derived class

52.

What is the output?

a)

Compile error

b)

Divide by zero error

c)

a = 0

Divide by zero error

inside the finally block

d)

a = 0

e)

inside the finally block

53.

What is the output?

a)

error occurred

End of the program

b)

Not Eligible for voting

End of the program

c)

Eligible for voting

End of the program

d)

none