wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Quiz (OOP Concepts & Exception Handling)

Total questions: 100

Worksheet time: 2hrs 40mins

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)

one

b)

one two

c)

one two 20

d)

20

e)

one 20

23.

A Package is the collection of

a)

classes

b)

interfaces

c)

classes and interfaces

d)

editing tools

e)

editing tools and interfaces

24.

which of these lines will give compile time error?

a)

1

b)

2

c)

3

d)

4

e)

None of these

25.

The class at the top of the exception hierarchy is

a)

ArithmeticException

b)

Throwable

c)

Object

d)

Exception

26.

in which package Exception class is available?

a)

java.util

b)

java.file

c)

java.io

d)

java.lang

e)

java.net

27.

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

a)

catch

b)

throw

c)

throws

d)

finally

28.

which keyword is used to explicitly throw an exception?

a)

try

b)

throwing

c)

catch

d)

throw

e)

throws

29.

which exception will through by decided by zero?

a)

NumberFormatException

b)

ArithmeticException

c)

NullPointerException

d)

None of these

30.

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

31.

What will be the output?

a)

inCatchBlock

b)

inCatchBlock inFinallyBlock

c)

inFinallyBlock

d)

The program will return without printing anything

32.

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

33.

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.

34.

what is the output?

a)

One

b)

Two

c)

One Two

d)

Compilation Error

35.

What is the output?

a)

"doCdoBdoA" is printed

b)

"doAdoBdoC" is printed

c)

"doBdoAerror" is printed

d)

"error" is printed

e)

nothing is printed

36.

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

37.

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

38.

Is this program create a new file with a.txt

a)

true

b)

false

c)

None of these

d)

Compilation Error

39.

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

40.

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

41.

What is the output?

a)

3

b)

3.5

c)

Compilation Error

d)

None of these

42.

what exception could be handled by catch block

a)

IllegalStateException

b)

ClassCastException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundsException

e)

None of these

43.

What is the output?

a)

Got the Exception 10

b)

Got the Exception 0

c)

Compiler Error

d)

none of the above

44.

What is the output?

a)

Got the Test Exception

Inside finally block

b)

Got the Test Exception

c)

Inside finally block

d)

Compiler Error

45.

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

46.

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

47.

Determine the output?

a)

one

b)

one two

c)

one two 20

d)

20

e)

one 20

48.

Read the Program

a)

1 and 2

b)

2 and 4

c)

3 and 4

d)

1 and 3

49.

Read the following code

a)

The keywords public and abstract cannot be used together.

b)

The method numberOfStudent() in class School must have a body.

c)

You must add a return statement in method numberOfStudent().

d)

Class School must be defined abstract.

50.

Which of the following is the legal abstract class?

a)

class A { abstract void unfinished() { } }

b)

class A { abstract void unfinished(); }

c)

abstract class A { abstract void unfinished(); }

d)

public class abstract A { abstract void unfinished(); }

51.

which of the following the abstract method in the abstract class?

a)

public abstract method();

b)

public abstract void method();

c)

public void abstract Method();

d)

public abstract void method() {}

52.

which of the following statements are true about abstract class?

a)

An abstract class can be extended.

b)

A subclass of a non-abstract superclass can be abstract.

c)

A subclass can override a concrete method in a superclass to declare it abstract.

d)

An abstract class can be used as a data type.

e)

All of the above

53.

read the statement

a)

1 and 2

b)

2 and 4

c)

3 and 4

d)

1 and 3

e)

2 and 3

54.

which of the following is correct about interface?

a)

interface A { void print() { } }

b)

abstract interface A { print(); }

c)

abstract interface A { abstract void print(); { }}

d)

interface A { void print(); }

55.

what is the output?

a)

Nothing.

b)

b is an instance of A.

c)

b is an instance of C.

d)

b is an instance of A followed by b is an instance of C.

56.

given the following piece of code

a)

This code will not compile, because method doYourJob() in interface Guard must be defined abstract.

b)

This code will not compile, because class Dog must implement method doYourJob() from interface Guard.

c)

This code will not compile, because in the declaration of class Dog we must use the keyword extends instead of implements.

d)

This code will compile without any errors.

57.

What will be the output?

a)

will print Class One method

b)

will print Class Two method

c)

compiles fine but print nothing

d)

Compilation Error

e)

None of these

58.

which of these lines will give compile time error?

a)

1

b)

2

c)

3

d)

4

e)

None of these

59.

What will happen after compiling this program?

a)

Successful run and print 37

b)

Compilation error due to line 1

c)

Compilation error due to line 2

d)

Runtime error

e)

None of these

60.

What is the output?

a)

Compilation fails due to an error on line 3

b)

A

c)

Compilation fails due to an error on line 8

d)

null

e)

None of these

61.

what will be the output?

a)

test-name

b)

Compilation fails due to an error on lines 2

c)

Compilation fails due to an error on lines 1

d)

Compilation succeed but Runtime Exception

e)

None of these

62.

What will be the output?

a)

Compile with error

b)

10

c)

12

d)

Runtime Exception

e)

None of these

63.

What is the output?

a)

The code will lead to a compilation error as declaration of the display method has been provided in two interface.

b)

The code will lead to a compilation error due to public modifier while declaring the display method.

c)

The code will compile and execute successfully showing the output Welcome to Examveda.

d)

The code will lead to a compilation error as the display method is not declared as abstract.

e)

None of these

64.

The class at the top of the exception hierarchy is

a)

ArithmeticException

b)

Throwable

c)

Class

d)

Exception

65.

in which package Exception class is available?

a)

java.util

b)

java.file

c)

java.io

d)

java.lang

e)

java.net

66.

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

a)

catch

b)

throw

c)

throws

d)

finally

67.

which keyword is used to explicitly throw an exception?

a)

try

b)

throwing

c)

catch

d)

throw

e)

throws

68.

which exception will through by decided by zero?

a)

NumberFormatException

b)

ArithmeticException

c)

NullPointerException

d)

None of these

69.

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

70.

What will be the output?

a)

inCatchBlock

b)

inCatchBlock inFinallyBlock

c)

inFinallyBlock

d)

The program will return without printing anything

71.

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

72.

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.

73.

what is the output?

a)

One

b)

Two

c)

One Two

d)

Compilation Error

74.

What is the output?

a)

"doCdoBdoA" is printed

b)

"doAdoBdoC" is printed

c)

"doBdoAerror" is printed

d)

"error" is printed

e)

nothing is printed

75.

Which of this keyword must be used to inherit a class?

a)

super

b)

this

c)

extent

d)

extends

76.

A class member declared protected becomes a member of subclass of which type?

a)

public member

b)

private member

c)

protected member

d)

static member

77.

Which of these is correct way of inheriting class A by class B?

a)

class B + class A {}

b)

class B inherits class A {}

c)

class B extends A {}

d)

class B extends class A {}

78.

What is the output of this program?

a)

0

b)

1

c)

2

d)

Compilation Error

79.

What is the output of this program?

a)

2 2

b)

3 3

c)

2 3

d)

3 2

80.

What is the output of this program?

a)

1 2

b)

2 1

c)

Runtime Error

d)

Compilation Error

81.

What is not type of inheritance?

a)

Single inheritance

b)

Double inheritance

c)

Hierarchical inheritance

d)

Multiple inheritance

82.

what is the output?

a)

Base

b)

Derived

c)

compile time error

d)

run-time error

83.

Output of following Java program?

a)

Base

Derived

Derived

b)

Base

Base

Derived

c)

Base

Derived

Base

d)

Compiler Error

84.

output of the program

a)

Base::show() called

b)

Compiler Error

c)

Derived::show() called

d)

None

85.

output of the program

a)

Base::show() called

b)

Derived::show() called

c)

Compiler Error

d)

Runtime Error

86.

Output of following Java Program?

a)

Derived::show() called

b)

compile time error

c)

Base::show() called

d)

runtime error

87.

Predict the output of following Java program?

a)

0

b)

garbage value

c)

compile time error

d)

runtime error

88.

Predict the output of following Java program

a)

garbage value

b)

0

c)

compile time error

d)

runtime error

89.

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

90.

Predict the output of the following program.

a)

Compilation error

b)

Inside First

Inside First

c)

Inside First

Inside Second

d)

Runtime error

91.

What is the output of the following JAVA program ?

a)

dogood : dogoodgood

b)

dogood : gooddogood

c)

dogood : dodogood

d)

dogood : dogood

92.

Predict the output?

a)

20

b)

0

c)

Compiler Error

d)

none

93.

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

94.

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

95.

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

96.

what is the output

a)

9.0 9.0

b)

9 9

c)

compile time error

d)

none

97.
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

98.

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?

a)

Public

b)

Protected

c)

No Modifier

d)

All of the mentioned

99.

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?

a)

Public

b)

Protected

c)

Private

d)

No Modifier

100.

A package is a collection of

a)

classes

b)

interfaces

c)

editing tools

d)

classes and interfaces