Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Access Modifiers, Inheritance & Polymorphism

Total questions: 39

Worksheet time: 52mins

Name
Class
Date
1.

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

a)

super

b)

this

c)

extent

d)

extends

2.

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

3.

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

4.

What is the output of this program?

a)

0

b)

1

c)

2

d)

Compilation Error

5.

What is the output of this program?

a)

2 2

b)

3 3

c)

2 3

d)

3 2

6.

What is the output of this program?

a)

1 2

b)

2 1

c)

Runtime Error

d)

Compilation Error

7.

What is not type of inheritance?

a)

Single inheritance

b)

Double inheritance

c)

Hierarchical inheritance

d)

Multiple inheritance

8.

what is the output?

a)

Base

b)

Derived

c)

compile time error

d)

run-time error

9.

Output of following Java program?

a)

Base

Derived

Derived

b)

Base

Base

Derived

c)

Base

Derived

Base

d)

Compiler Error

10.

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

11.

output of the program

a)

Base::show() called

b)

Compiler Error

c)

Derived::show() called

d)

None

12.

output of the program

a)

Base::show() called

b)

Derived::show() called

c)

Compiler Error

d)

Runtime Error

13.

Output of following Java Program?

a)

Derived::show() called

b)

compile time error

c)

Base::show() called

d)

runtime error

14.

Predict the output of following Java program?

a)

0

b)

garbage value

c)

compile time error

d)

runtime error

15.

Predict the output of following Java program

a)

garbage value

b)

0

c)

compile time error

d)

runtime error

16.

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

17.

Predict the output of the following program.

a)

Compilation error

b)

Inside First

Inside First

c)

Inside First

Inside Second

d)

Runtime error

18.

What is the output of the following JAVA program ?

a)

dogood : dogoodgood

b)

dogood : gooddogood

c)

dogood : dodogood

d)

dogood : dogood

19.

Predict the output?

a)

20

b)

0

c)

Compiler Error

d)

none

20.

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

21.

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

22.

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

23.

What is the output of this program?

a)

2

b)

3

c)

7

d)

compile time error

24.

what is the output

a)

9.0 9.0

b)

9 9

c)

compile time error

d)

none

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

26.

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

27.

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

28.

Which of the following is an incorrect statement about packages?

a)

Package defines a namespace in which classes are stored

b)

A package can contain other package within it

c)

Java uses file system directories to store packages

d)

A package can be renamed without renaming the directory in which the classes are stored

29.

For which purpose packages are used in Java?

a)

Categorizes data

b)

Organizing java classes into namespaces

c)

faster compilation

d)

None of These

30.

A package is a collection of

a)

classes

b)

interfaces

c)

editing tools

d)

classes and interfaces

31.

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.

32.

which package is imported implicitly?

a)

java.applet

b)

java.util

c)

java.lang

d)

java.io

33.

Math class is in ………package.

a)

java.io

b)

java.lang

c)

java.util

d)

java.applet

34.

………………….. package in java contents language utility classes such as vectors, hash tables, random numbers date etc.

a)

java.util

b)

java.awt

c)

java.net

d)

java.lang

35.

…………………….. package in java contents set of classes for implementing graphical user interface, which includes classes for windows, buttons, lists, menus and so on.

a)

java.util

b)

java.awt

c)

java.net

d)

java.lang

36.

Which keyword can protect a class in a package from accessibility by the classes outside the package.

i) private ii) protected iii) final

a)

i only

b)

ii only

c)

iii only

d)

None of the above

37.

Which of the following classes in Java.io package defines a method to delete a file.

a)

Stack

b)

File

c)

String

d)

Vector

38.

The Date class includes within ………………….. package.

a)

java.io

b)

java.awt

c)

java.net

d)

java.util

39.

By convention, java packages begin with ………………. letters while all the class names begin with an ………………… letter.

a)

uppercase, uppercase

b)

lowercase, lowercase

c)

uppercase, lowercase

d)

lowercase, uppercase