wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java_Quiz_Three

Total questions: 20

Worksheet time: 12mins

Name
Class
Date
1.

Output of following Java Program?

a)

Derived::show() called

b)

Base::show() called

c)

Run time Error

d)

Compilation Error

2.

What will be the output of following program?

a)

Base::show() called

b)

Derived::show() called

c)

Compiler Error

d)

Runtime Error

3.

Which inheritance in java programming is not supported

a)

Multiple inheritance using classes

b)

Multiple inheritance using interfaces

c)

Multilevel inheritance

d)

Single inheritance

4.

Predict the output of following program

a)

Base

b)

Derived

c)

Compiler Error

d)

Runtime Error

5.

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

6.

In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?

a)

Protected

b)

Private

c)

Public

d)

Static

7.

If super class and subclass have same variable name, which keyword should be used to use super class?

a)

super

b)

this

c)

upper

d)

classname

8.

Order of execution of constructors in Java Inheritance is

a)

Base to derived class

b)

Derived to base class

c)

Random order

d)

none

9.

In a Multi-Level Inheritance in Java, the last subclass inherits methods and properties of ____.

a)

Only one immediate Superclass

b)

Few classes above it.

c)

All classes above it

d)

None of the mentioned

10.

Class Cat extends Animal. Which is NOT a valid declaration?

a)

Cat x = new Cat();

b)

Animal X = new Animal();

c)

Cat x = new Animal();

d)

Animal x = new Cat();

11.
What does polymorphism mean?
a)
Changing shapes
b)
Having many forms
c)
Being unchangeable
d)
Easy
12.

When overloading a method, the method header ________ .

a)

Must exactly match the header of the method you are overloading.

b)

Must have the same name, but differ in order, number, or type of parameters.

c)

Can differ in name, but must have the same number and order of parameters.

d)

Can be completely different from the method you are overloading, but must have @Override.

13.
A(n) ____________________ method cannot be overridden by a subclass.
a)
final
b)
private
c)
public
d)
static
14.
When the subclass method is intended as a replacement of the superclass method.
a)
Overriding
b)
Dependency
c)
Extension
d)
Aggregation
15.

What is the output of this program?

a)

0

b)

1

c)

2

d)

Compilation Error

16.

What is the output of this program?

a)

2 2

b)

3 3

c)

2 3

d)

3 2

17.

What is the output of this program?

a)

1 2

b)

2 1

c)

Runtime Error

d)

Compilation Error

18.
Inheritance is used when the relationship between two classes is a(n) _______ relationship.
a)
"HAS-A"
b)
"PART-OF-A"
c)
"IS-A"
d)
inverse
19.

Which of the following is/are false about inheritance in Java?

I. A subclass inherits all the methods and variables of the superclass.

II. A subclass can override the methods of its superclass

III. A subclass has access to the private instance variables of the superclass.

a)

I only

b)

II only

c)

III only

d)

I and II only

e)

I and III only

20.

super keyword is used to access

a)

only subclass methods

b)

parent class variables and methods

c)

subclass variables and methods

d)

only parent class methods