wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

polymorphism, exception and packages

Total questions: 40

Worksheet time: 24mins

Name
Class
Date
1.

the class at the top of exception class hierarchy is ...

a)

ArithmeticException

b)

Throwable

c)

Object

d)

Exception

2.

in which of the following package exception class exists

a)

java.lang

b)

java.io

c)

java.util

d)

java.net

3.

a)

0.0

b)

Compilation fails.

c)

A Parse Exception is thrown by the parse method at runtime.

d)

A Number Format Exception is thrown by the parse method at runtime.

4.

Under which three circumstances will the code on line 37 be executed?

a)

The instance gets garbage collected.

b)

The code on line 33 throws an exception.

c)

The code on line 35 throws an exception.

d)

The code on line 31 throws an exception.

e)

The code on line 33 executes successfully.

5.

Which exception or error will be thrown when a programmer attempts to run this code?

a)

java.lang.StackOverflowError

b)

java.lang.IllegalStateException

c)

java.lang.ExceptionInInitializerError

d)

java.lang.ArrayIndexOutOfBoundsException

6.
a)

null

b)

life

c)

universe

d)

everything

e)

Compilation fails.

7.

a)

Compilation Error

b)

A

c)

B

d)

Runtime error

8.

Which of these keywords must be used to monitor for exceptions?

a)

finally

b)

catch

c)

try

d)

throw

e)

throws

9.
a)

hello throwit caught

b)

Compilation fails

c)

hello throwit caught finally after

d)

hello throwit RuntimeException caught after

10.

a)

12345

b)

123450

c)

1234500

d)

Compilation Error

11.

which of the following are valid

a)

1,3

b)

2,3,4

c)

1,4

d)

1,2,3,4,5

12.

The ability to define more than one function with the same name is called?

a)

Inheritance

b)

Encapsulation

c)

Abstraction

d)

Polymorphism

13.

Which of the following is the correct way of importing an entire package "pkg"?

a)

import pkg.

b)

Import pkg.

c)

import pkg.*

d)

Import pkg.*

14.

Choose the correct syntax of a Java Package below.

a)

package PACKAGE_NAME;

b)

package PACKAGE_NAME.*;

c)

pkg PACKAGE_NAME;

d)

pkg PACKAGE_NAME.*;

15.

Package in Java is a mechanism to encapsulate a ______________.

a)

Classes

b)

Sub Packages

c)

Interfaces

d)

All of the above

16.

Is it necessary that each try block must be followed by a catch block?

a)

True

b)

False

17.

which of the following is an example of polymorphism design related to switch board plugs.

a)
b)
c)
d)
e)
18.

this is an example for

a)

method overloading

b)

method overriding

19.

Choose the correct syntax below for defining an Interface in Java.

a)
b)
c)
d)

All the above

20.
a)

no output

b)

C

c)

compile time error

d)

none of the above

21.

which of the package contains Scanner class

a)

import java.io.*;

b)

import java.net.*;

c)

import java.util.*;

d)

import java.awt.*;

22.

Which of the following key word is optional in Exception handling program

a)

try

b)

catch

c)

finally

d)

throw

23.

What is the purpose of 'throw' keyword

a)

To Raise an exception explicityly

b)

To Raise an exception implicityly

c)

To create user defined exceptions

d)

To create custom exceptions

24.

Choose the CORRECT exception


String clg="LBRCE";

Integer no=Integer.parseInt(clg);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundsException

25.

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

26.

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 {}

27.

What is the output of this program?

a)

0

b)

1

c)

2

d)

Compilation Error

28.

What is the output of this program?

a)

2 2

b)

3 3

c)

2 3

d)

3 2

29.

What is the output of this program?

a)

1 2

b)

2 1

c)

Runtime Error

d)

Compilation Error

30.

What is not type of inheritance?

a)

Single inheritance

b)

Double inheritance

c)

Hierarchical inheritance

d)

Multiple inheritance

31.

what is the output?

a)

Base

b)

Derived

c)

compile time error

d)

run-time error

32.

Output of following Java program?

a)

Base

Derived

Derived

b)

Base

Base

Derived

c)

Base

Derived

Base

d)

Compiler Error

33.

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

34.

output of the program

a)

Base::show() called

b)

Compiler Error

c)

Derived::show() called

d)

None

35.

output of the program

a)

Base::show() called

b)

Derived::show() called

c)

Compiler Error

d)

Runtime Error

36.

Output of following Java Program?

a)

Derived::show() called

b)

compile time error

c)

Base::show() called

d)

runtime error

37.

Math class is in ………package.

a)

java.io

b)

java.lang

c)

java.util

d)

java.applet

38.

which package is imported implicitly?

a)

java.applet

b)

java.util

c)

java.lang

d)

java.io

39.

If a variable is declared as private , then it can be used in _______.

a)

Any class of any package.

b)

Any class of same package.

c)

Only in the same class.

d)

Only subclass in that package.

40.

A package is a collection of

a)

classes

b)

interfaces

c)

editing tools

d)

classes and interfaces