Types of Inheritance in Java4 min read

Java supports three types of inheritance on the basis of class :
single, multilevel and hierarchical.
Whereas multiple and hybrid inheritance is supported through interface only.Types:

Java: Types of Inheritance:

  • Single Inheritance
  • Multilevel Inheritance.
  • Hierarchical Inheritance.
  • Multiple Inheritance.
  • Hybrid Inheritance.

1. Single Inheritance:

It is a child and parent class relationship where a child class extends or inherits only from one class or superclass.
In the below diagram, class B extends only one class which is A. Here class A is a parent class of B and B would be a child class of A.

Single Inheritance
Java Single Inheritance

Example of Single Inheritance in Java:

Output of single Inheritance:


2. Multilevel Inheritance:

It is a child and parent class relationship where one can inherit from a derived class, thereby making this derived class the base class for the new class.
In the below diagram, class C is a subclass or child class of class B and class B is a child class of class A.

Multilevel Inheritance
Java Multilevel Inheritance

Example of Multilevel Inheritance in Java:

Output of Multilevel Inheritance:


3. Hierarchical Inheritance:

In this type of inheritance, one superclass(base class) is inherited by many subclasses (derived class). That is inheriting the same class by many classes.
In the below diagram class B and class, C inherits the same class A. Class A is parent class (or base class) of class B and class C.

Hierarchical Inheritance
Java Hierarchical Inheritance

Example of Multilevel Inheritance in Java:

Output of Multilevel Inheritance:


4. Multiple Inheritance:

In this relationship, one class(derived class) can inherit from more than one superclass. Java doesn’t support multiple inheritance because the derived class will have to manage the dependency on two base classes.
In java, we can achieve multiple inheritance only through Interfaces.
It is rarely used because it creates an unwanted problem in the hierarchy.


5. Hybrid Inheritance:

It is the relationship form by the combination of multiple inheritance.
In a simple way, Hybrid inheritance is a combination of Single and Multiple inheritance.
It is also not supported in Java and can only be achieved through interface just like Multiple Inheritance.

Multiple and Hybrid Inheritance diagram:

Inheritance
Supported through Interfaces

Inheritance.
OOP (Object-Oriented Programming) in java.