Here are 10 essential multiple-choice questions on Java Inheritance and Abstraction, covering key concepts.
Question 1
Which of the following statements about the Object class in Java is true?
Every Java class extends Object class either directly or indirectly.
Only classes without a superclass extend Object class.
The Object class cannot be extended.
Object class is an abstract class.
Question 2
What will be the output of the following code?
class A {
void display() {
System.out.println("Class A");
}
}
class B extends A {
void display() {
System.out.println("Class B");
}
}
public class Main {
public static void main(String[] args) {
A obj = new B();
obj.display();
}
}
Class A
Class B
Compilation error
Runtime error
Question 3
Which keyword is used to create a subclass in Java?
implements
inherits
extends
interface
Question 4
Which keyword is used to refer to the immediate parent class in Java?
this
super
extends
parent
Question 5
What will be the output of this program?
abstract class Parent {
abstract void show();
}
class Child extends Parent {
void show() {
System.out.println("Child class method");
}
}
public class Main {
public static void main(String[] args) {
Parent p = new Child();
p.show();
}
}
Compilation Error
Runtime Error
Child class method
No Output
Question 6
What happens if an abstract class does not have any abstract methods?
It will not compile.
The class can still be abstract.
Java will automatically provide an abstract method.
It becomes a concrete class.
Question 7
What will be the output of this code?
class Animal {
void makeSound() {
System.out.println("Animal makes a sound");
}
}
class Dog extends Animal {
void makeSound() {
System.out.println("Dog barks");
}
}
public class Main {
public static void main(String[] args) {
Animal a = new Dog();
a.makeSound();
}
}
Animal makes a sound
Dog barks
Compilation error
Runtime error
Question 8
Which of the following statements about inheritance is false?
Java supports single inheritance.
Java allows multiple class inheritance using extends.
Interfaces can be used to achieve multiple inheritance.
The super keyword can be used to invoke the parent class constructor.
Question 9
Which of the following statements about abstract classes is correct?
Abstract classes cannot have constructors.
Abstract classes cannot have static methods.
An object of an abstract class cannot be instantiated.
Abstract classes cannot have final methods.
Question 10
Which of the following correctly describes the relationship between interfaces and abstract classes in the context of inheritance?
Abstract classes can implement interfaces and provide default method implementations.
Interfaces can extend abstract classes.
Interfaces must be extended using the extends keyword only by other interfaces.
An abstract class can extend multiple interfaces directly.
There are 10 questions to complete.