MCQs on Inheritance in Java
Q1. Which of the following is used to inherit a class in Java?
a) super
b) extends
c) this
d) implements
Answer: b) extends
Q2. In Java, which type of inheritance is not supported directly?
a) Single
b) Multilevel
c) Hierarchical
d) Multiple
Answer: d) Multiple
Q3. Which keyword is used to call the parent class constructor?
a) this()
b) parent()
c) super()
d) base()
Answer: c) super()
Q4. If a class does not explicitly extend another class, it automatically inherits from:
a) Null class
b) Object class
c) Base class
d) None
Answer: b) Object class
Q5. What will be the output of the following code?
class A {
int x = 10;
}
class B extends A {
int x = 20;
}
public class Test {
public static void main(String[] args) {
B obj = new B();
System.out.println(obj.x);
}
}
a) 10
b) 20
c) Compilation error
d) Runtime error
Answer: b) 20
Q6. Which keyword is used to access the immediate parent class variable when it is hidden
by child class variable?
a) this
b) super
c) extends
d) base
Answer: b) super
Q7. Inheritance promotes:
a) Data redundancy
b) Code reusability
c) Code repetition
d) Both a and c
Answer: b) Code reusability
Q8. Which type of inheritance is achieved through interfaces in Java?
a) Single
b) Multiple
c) Multilevel
d) Hierarchical
Answer: b) Multiple
Q9. Consider the code:
class Parent {
void show() { System.out.println("Parent"); }
}
class Child extends Parent {
void show() { System.out.println("Child"); }
}
public class Test {
public static void main(String[] args) {
Parent obj = new Child();
obj.show();
}
}
What is the output?
a) Parent
b) Child
c) Compilation error
d) Runtime error
Answer: b) Child
Q10. Which of the following cannot be inherited?
a) Methods
b) Constructors
c) Variables
d) Nested classes
Answer: b) Constructors
Q11. Which access modifier allows a member to be inherited but not accessible outside the
package?
a) private
b) public
c) protected
d) default (no modifier)
Answer: c) protected
Q12. What will be the result of calling super() in a child class constructor?
a) Calls the parent class constructor
b) Calls the current class constructor
c) Calls main() method
d) Causes compilation error
Answer: a) Calls the parent class constructor
Q13. Which inheritance model does Java primarily support?
a) Single and multiple
b) Single, multilevel, hierarchical
c) Only multiple
d) Hybrid by default
Answer: b) Single, multilevel, hierarchical
Q14. When a method in a subclass has the same signature as in superclass, it is known as:
a) Overloading
b) Overriding
c) Hiding
d) Shadowing
Answer: b) Overriding
Q15. Which of the following is true about method overriding?
a) Return type must always be same
b) Access modifier in subclass cannot be more restrictive
c) Static methods can be overridden
d) Constructors can be overridden
Answer: b) Access modifier in subclass cannot be more restrictive
Q16. What happens if both parent and child have the same data member variable?
a) Ambiguity error
b) Parent’s variable is accessible only
c) Child’s variable hides parent’s variable
d) Compilation error
Answer: c) Child’s variable hides parent’s variable
Q17. Which concept of OOP is implemented using inheritance in Java?
a) Encapsulation
b) Polymorphism
c) Abstraction
d) Both b and c
Answer: d) Both b and c
Q18. If a child class object is referred by a parent class reference variable, which methods are
executed?
a) Parent’s only
b) Child’s only
c) Depends on object creation (Dynamic Binding)
d) Compilation error
Answer: c) Depends on object creation (Dynamic Binding)
Q19. Which keyword is used to prevent a class from being inherited?
a) abstract
b) static
c) final
d) constant
Answer: c) final
Q20. What will be the output?
class A {
A() { System.out.println("A"); }
}
class B extends A {
B() { System.out.println("B"); }
}
public class Test {
public static void main(String[] args) {
B obj = new B();
}
}
a) B A
b) A B
c) Compilation error
d) Runtime error
Answer: b) A B
Here are 5 Assertion & Reason type questions based on Inheritance in Java (Class 12
level):
Assertion & Reason Questions (Inheritance in Java)
Q21.
Assertion (A): In Java, constructors are not inherited.
Reason (R): A subclass can call the parent constructor using the super() keyword.
• a) Both A and R are true, and R is the correct explanation of A
• b) Both A and R are true, but R is not the correct explanation of A
• c) A is true, R is false
• d) A is false, R is true
Answer: a) Both A and R are true, and R is the correct explanation of A
Q22.
Assertion (A): Method overriding is used to achieve runtime polymorphism in Java.
Reason (R): Overriding allows a subclass to provide a specific implementation of a method
already defined in its parent class.
• a) Both A and R are true, and R is the correct explanation of A
• b) Both A and R are true, but R is not the correct explanation of A
• c) A is true, R is false
• d) A is false, R is true
Answer: a) Both A and R are true, and R is the correct explanation of A
Q23.
Assertion (A): Java does not support multiple inheritance using classes.
Reason (R): This restriction is to avoid ambiguity caused by the Diamond Problem.
• a) Both A and R are true, and R is the correct explanation of A
• b) Both A and R are true, but R is not the correct explanation of A
• c) A is true, R is false
• d) A is false, R is true
Answer: a) Both A and R are true, and R is the correct explanation of A
Q24.
Assertion (A): A subclass can access private members of its parent class directly.
Reason (R): Private members are inherited but not accessible outside the class.
• a) Both A and R are true, and R is the correct explanation of A
• b) Both A and R are true, but R is not the correct explanation of A
• c) A is false, R is true
• d) Both A and R are false
Answer: c) A is false, R is true
Q25.
Assertion (A): The final keyword can be used to prevent method overriding.
Reason (R): A method declared as final cannot be redefined in the child class.
• a) Both A and R are true, and R is the correct explanation of A
• b) Both A and R are true, but R is not the correct explanation of A
• c) A is true, R is false
• d) A is false, R is true
Answer: a) Both A and R are true, and R is the correct explanation of A