wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Inheritance Java

Total questions: 132

Worksheet time: 29mins

Name
Class
Date
1.

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

a)

super

b)

this

c)

extends

d)

extent

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.

class A

{

int i;

void display()

{

System.out.println(i);

}

}

class B extends A

{

int j;

void display()

{

System.out.println(j);

}

}

class inheritance_demo

{

public static void main(String args[])

{

B obj = new B();

obj.i=1;

obj.j=2;

obj.display();

}

}

a)

0

b)

1

c)

2

d)

Compilation Error

4.

What will be the output of the following Java program?

class A

{

int i;

}

class B extends A

{

int j;

void display()

{

super.i = j + 1;

System.out.println(j + " " + i);

}

}

class inheritance

{

public static void main(String args[])

{

B obj = new B();

obj.i=1;

obj.j=2;

obj.display();

}

}

a)

2 2

b)

3 3

c)

2 3

d)

3 2

5.

Using which of the following, multiple inheritance in Java can be implemented?

a)

Interfaces

b)

Multithreading

c)

Protected methods

d)

Private methods

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.

Which inheritance in java programming is not supported

a)

Multiple inheritance using classes

b)

Multiple inheritance using interfaces

c)

Multilevel inheritance

d)

Single inheritance

9.

If class B is subclassed from class A then which is the correct syntax

a)

class B:A{}

b)

class B extends A{}

c)

class B extends class A{}

d)

class B implements A{}

10.

Order of execution of constructors in Java Inheritance is

a)

Base to derived class

b)

Derived to base class

c)

Random order

d)

none

11.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
12.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
13.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
14.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
15.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
16.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
17.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
18.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
19.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
20.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
21.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
22.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
23.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
24.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
25.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
26.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
27.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
28.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
29.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
30.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
31.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
32.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
33.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
34.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
35.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
36.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
37.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
38.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
39.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
40.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
41.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
42.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
43.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
44.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
45.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
46.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
47.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
48.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
49.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
50.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
51.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
52.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
53.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
54.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
55.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
56.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
57.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
58.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
59.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
60.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
61.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
62.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
63.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
64.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
65.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
66.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
67.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
68.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
69.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
70.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
71.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
72.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
73.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
74.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
75.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
76.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
77.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
78.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
79.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
80.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
81.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
82.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
83.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
84.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
85.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
86.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
87.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
88.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
89.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
90.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
91.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
92.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
93.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
94.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
95.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
96.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
97.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
98.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
99.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
100.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
101.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
102.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
103.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
104.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
105.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
106.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
107.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
108.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
109.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
110.
Identify if the image is related to 'Inheritance + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
111.

Inheritance means

a)

Sub class extends Base class

b)

Sub class extends super class

c)

Sub class create object of super class

d)

All of the above

112.

What type of inheritance does Java have?

a)

Single Inheritance

b)

Double Inheritance

c)

Multiple Inheritance

d)

Class Inheritance

113.

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

a)

extends

b)

extent

c)

super

d)

this

114.

What is not type of inheritance?

a)

Single Inheritance

b)

Double Inheritance

c)

Multiple Inheritance

d)

Class Inheritance

115.

What are the features reused using Inheritance in Java?

a)

Variables

b)

Constants

c)

Methods

d)

All the above

116.

Which inheritance in java programming is not supported?

a)

Single inheritance

b)

Multilevel inheritance

c)

Multiple inheritance using classes

d)

Multiple inheritance using interfaces

117.

A ........... is a group of objects which have common properties.

a)

Class

b)

Sub Class

c)

Super Class

d)

None

118.

.............. is a class which inherits the other class.

a)

Class

b)

Sub Class

c)

Super Class

d)

None

119.

................. is the class from where a subclass inherits the features.

a)

Class

b)

Sub Class

c)

Super Class

d)

None

120.

Subclass is also called a ...........

a)

Derived Class

b)

Extended Class

c)

Child Class

d)

All the above

121.

Superclass is also called a ...............

a)

Base Class

b)

Parent Class

c)

Both A and B

d)

None

122.

is an example of

a)

Single Inheritance

b)

Multiple Inheritance

c)

Multilevel Inheritance

d)

None

123.
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
124.

The following Syntax is used for?


class Subclass-name extends Superclass-name

{

//methods and fields

}

a)

Polymorphism

b)

Encapsulation

c)

Inheritance

d)

None of the above

125.

A class that is inherited is called a ______ .

a)

superclass

b)

Subclass

c)

subsetclass

d)

Relativeclass

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

When an object's class is a subclass of a more general class.

a)

Extension

b)

Aggregation

c)

Inheritance

d)

Dependency

128.

Which Java statement represents inheritance?

a)

class body inherit Car

b)

class body super Car

c)

class body extends Car

d)

class body this Car

e)

class body override Car

129.

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

130.

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

131.

What is the output of following Java Program?


class Online

{

public

void print()

{

System.out.println("Online::print() called");

}

}


class OOP extends Online

{

public

void print()

{

System.out.println("OOP::print() called");

}

}


public class Main

{

public static void main(String[] args)

{

OOP ob =new OOP();

ob.print();

}

}

a)

Online::print() called

b)

OOP::print() called

132.

Consider the following code.


class Vehicle

{

int maxSpeed = 120;

}

class Car extends Vehicle

{

int maxSpeed = 180;

void display() {

System.out.println("Maximum Speed: " + super.maxSpeed);

}

}


/* Driver program to test */

class Test

{

public static void main(String[] args)

{

Car small = new Car(); small.display();

}

}


In the program output, what is the maximum speed displayed?

a)

120

b)

180

c)

120 dan 180

d)

semua salah