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.

Types of Inheritance in Java:

  • 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:

Super class method
Base class method

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:

I am First Class
I am Second Class
I am Third Class

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:

I am dog
I am Horse and I run
I am dog
I am Cat and I sleep

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 find the sum of the Largest Forward Diagonal

in this tutorial, we will write a java program to find the sum of the Largest Forward Diagonal in an Arraylist (matrix). Java Program to …

C Program to search an element in an array using Pointers

A separate function( search_function()) will be created where the array pointer will be declared and the searched element along with the size of an array …

C Program to find the sum of the digits of a number using recursion function

This C program calculates the sum of digits of a given number using recursion. Here’s a concise explanation: Function Definition: sumDigits(int n) This function calculates …

C program to find factorial of a number using Ternary operator with Recursion

Recursion refers to the function calling itself directly or in a cycle. Before we begin, you should have the knowledge of following in C Programming: …

C Program to Add Two Numbers Using Call by Reference

The program takes the two numbers from the user and passes the reference to the function where the sum is calculated. You may go through …

Find the output ab, cd, ef, g for the input a,b,c,d,e,f,g in Javascript and Python

In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will …