Java – Types of Inheritance4 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.

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

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

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

Example of Hierarchical Inheritance in Java:

Output of Hierarchical 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:

Supported through Interfaces


Java Program to check Krishnamurthy Number

In this tutorial, we will learn about Krishnamurthy numbers and write a Krishnamurthy Number program in Java. We will write two programs for Krishnamurthy number …
Read More

Java Program for ISBN Number

In this tutorial, we will learn about the ISBN (International Standard Book Number) and write a program to check for the ISBN Number in Java …
Read More

C++ Memory Management

Memory management refers to the process of managing the computer memory while assigning the space to the program’s variable to improve the overall performance. Requirement …
Read More

C++ Pointer to Pointer

As we know by now that a pointer stores the address of the pointed variable. But it is not the only use, pointer also stores …
Read More

C++ Passing Pointers to Functions

A function is a user-defined block of codes that executes some specific task assigned to it invoked by its name. If there is an argument …
Read More

C++ Null Pointer

We use a null pointer when we do not have the exact address to assign to a pointer. It is considered a good practice and …
Read More