Java Inheritance Interview MCQ Questions and Answers

Study and learn Interview MCQ Questions and Answers on Inheritance in Java. You can know about Multilevel and Multiple Inheritances. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save as PDF option next using any Web Browser.

Go through Java Theory Notes on Inheritance before reading these objective questions.



1) What are the features of an Object Oriented Programming (OOPs)?
A) Inheritance
B) Encapsulation
C) Polymorphism
D) All the above
Answer [=]
D
2) What are the features reused using Inheritance in Java?
A) Methods
B) Variables
C) Constants
D) All the above
Answer [=]
D
Explanation:

Variables and Methods are reused through inheritance. Constants are nothing but variables only if they hold some value. 

3) The class that is being inherited or subclassed is called ___.
A) Subclass
B) Superclass
C) -
D) -
Answer [=]
B
Explanation:

Superclass or Super-Class

4) The class that inherits an already defined class is called ___.
A) Subclass
B) Superclass
C) -
D) -
Answer [=]
A
Explanation:

Subclass

5) Java language supports ___ type of inheritance.
A) Multiple Inheritance
B) Multi-Level Inheritance
C) -
D) -
Answer [=]
B
Explanation:

Multi-Level Inheritance is somewhat complicated.

6) You should use Inheritance when there is an IS-A relationship between classes. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
A
Explanation:

Yes. One simple example is ANIMAL Superclass and HORSE Subclass. HORSE is-a/is-an ANIMAL.

7) What are the types of Inheritances (Whether Java supports or not) available in Object-Oriented Programming Languages?
A) Single Inheritance
B) Multi-Level Inheritance, Hierarchical Inheritance
C) Multiple Inheritance, Hybrid Inheritance
D) All the above
Answer [=]
D
Explanation:

Java supports extending from only one Superclass. Multilevel inheritance is completely supported by Java. Whereas Multiple and Hybrid inheritances are based on Multiple-Superlclasses scenario and hence not supported by Java.



8) In a Single inheritance, Class B inherits only from Class A. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
A
Explanation:

True.

9) In a Multi Level Inheritance Class-C inherits from Class-B and Class-B inherits from Class-A. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
A
Explanation:

True

10) In a Multi-Level Inheritance in Java, the last subclass inherits methods and properties of ____.
A) Only one immediate Superclass
B) Few classes above it.
C) All classes above it
D) None
Answer [=]
C
Explanation:

Yes. The last class inherits all of the properties and methods of all of the classes above it in the chain.

11) When a Class inherits two superclasses (not in Java), it is called ____ inheritance.
A) Multilevel inheritance
B) Single Inheritance
C) Multiple Inheritance
D) None
Answer [=]
C
Explanation:

Multiple Inheritance

12) A Subclass can become a Superclass to another class extending from it in Java. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
A
Explanation:

Yes, true.

13) You can not inherit a Superclass'es constructor even after using inheritance in Java. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
A
Explanation:

Yes. True. A Constructor is class-specific. It is not like a method that can be shared.

14) Find Superclass and Subclass in the below Java code snippet?
class B
{
  void show(){}
}
class A
{
  void hide(){}
}
A) B is superclass and A is subclass.
B) A is superclass and B is a subclass.
C) There is no superclass or subclass present.
D) None
Answer [=]
C
Explanation:

As there is no use of the "extends" keyword, inheritance does not come into the picture. So, there is no superclass or subclass present in the above example.



15) Find Superclass and Subclass in the below Java program?
class Liquid
{
  void pour(){}
}
class Juice extends Liquid
{
  void filter(){}
}
A) The Liquid is a superclass and Juice is a subclass.
B) The Liquid is a Subclass and Juice is a Superclass.
C) There is no superclass or subclass
D) None
Answer [=]
A
Explanation:

As the Juice class is extending from the Liquid class, Juice is a subclass and Liquid is a superclass. Simply put, the class before the "extends" keyword is always a Subclass.

16) Which is the keyword used to implement inheritance in Java?
A) extends
B) implements
C) instanceof
D) None
Answer [=]
A
Explanation:

The keyword "extends" tells the compiler that the class on the left side is subclassing the class on the right side.

17) What is the output of the below Java program with inheritance?
class Sweet
{
  void price()
  {
    System.out.print("Sweet=$10 ");
  }
}
class Sugar extends Sweet
{
  void price()
  {
    super.price();
    System.out.print("Sugar=$20");
  }
}
public class JavaInheritance1
{
  public static void main(String[] args)
  {
    Sugar su = new Sugar();
    su.price();
  }
}
A) Sweet=$10 Sugar=$20
B) Sweet=$10 Sugar=$10
C) Sweet=$20 Sugar=$20
D) Compiler error
Answer [=]
A
Explanation:

Notice the use of the keyword "super". Using this keyword, you can call superclass's methods and variables.

18) Can you call it a full-fledged inheritance of using ABSTRACT classes and INTERFACES in Java?
A) NO
B) YES
C) -
D) -
Answer [=]
A
Explanation:

No. Abstract classes and Interfaces do not define a class completely. So, it is not called a full-fledged inheritance of using those.

19) To control inheritance to different classes and levels, Java provides ____.
A) Return types like the void, int, float, double and other object types
B) Static keyword
C) Access modifiers like default, public, protected, private
D) None
Answer [=]
C
Explanation:

Access modifiers like default (not a keyword), public, protected and private changed the visibility of a method, variable or a class. Even the keyword "package" also allows grouping of classes and control inheritance levels to some extent.

20) To stop or block inheriting a given class, the ___ keyword is used before the class.
A) static
B) private
C) final
D) none of the above
Answer [=]
C
Explanation:

You can not subclass a class that is marked FINAL.

final class CLASS_NAME //Can not subclass
{

}
class SUBCLASS extends CLASS_NAME //ERROR
{

}