menu

Inheritance in Java


1. Which type of inheritance allows a class to inherit properties and behavior from multiple parent classes?

Single inheritance

Multiple inheritance

Multilevel inheritance

Hybrid inheritance


2. Which keyword is used to create an abstract class in Java?

abstract

final

static

synchronized


3. What is the first method that is executed when an object of a class is created?

finalize()

constructor

main()

start()


4. Which keyword is used to create an interface in Java?

abstract

interface

implements

extends


5. Which keyword is used to implement an abstract method in a subclass in Java?

abstract

final

static

override


6.

What is the output of the following program?

class A {
int x = 10;
}
class B extends A {
int x = 20;
}
public class Main {
public static void main(String[] args) {
A obj1 = new A();
B obj2 = new B();
System.out.println(obj1.x);
System.out.println(obj2.x);
}
}

10, 20

20, 20

10, 10

Compilation error


7.

What is the output of the following program?

class A {
int x = 10;
}
class B extends A {
int y = 20;
}
class C extends B {
void display() {
System.out.println(x + y);
}
}
public class Main {
public static void main(String[] args) {
C obj = new C();
obj.display();
}
}

30

20

10

Compilation error


8. What is the name of the process of creating a new class by extending an existing class?

Abstraction

Polymorphism

Inheritance

Encapsulation


9. Which of the following statements is true regarding the 'this' keyword in Java?

It can be used to access a static field of a class.

It can be used to call a method of a superclass.

It can be used to refer to the current instance of a class.

It can be used to declare a constructor.


10. Which keyword is used to invoke the constructor of the parent class?

this

super

extends

implements