MCQs – Java Inheritance

(Last Updated On: March 13, 2019)
Q) Which inheritance in java programming is not supported
  1. Multiple inheritance using classes
  2. Multiple inheritance using interfaces
  3. Multilevel inheritance
  4. Single inheritance
View Answer
Answer: A

NOTE: Java does not support multiple inheritance of classes but it supports multiple inheritance for interfaces. Means, a class cannot inherit more than one class but it can inherit and implement multiple interfaces.


Q) What is subclass in java?
  1. A subclass is a class that extends another class
  2. A subclass is a class declared inside a class
  3. Both above.
  4. None of the above.
View Answer
Answer: A
A subclass is a class that extends another class. In other words, subclass inherits the functionality of the class it extends. See below example.
Base class

Q) If class B is subclassed from class A then which is the correct syntax
  1. class B:A{}
  2. class B extends A{}
  3. class B extends class A{}
  4. class B implements A{}
View Answer
Answer: B
Below is the example

Q) Order of execution of constructors in Java Inheritance is
  1. Base to derived class
  2. Derived to base class
  3. Random order
  4. none
View Answer
Answer: A
On object creation of derived class, first base class constructor and then derived class constructor will be called.
Below is the java code example
Base Constructor
Derived Constructor