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.

Example of Single Inheritance in Java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | class SuperClass { public void methodSuper() { System.out.println("Super class method"); } } class SubClass extends SuperClass { public void methodBase() { System.out.println("Sub class method"); } } public class Main { public static void main(String args[]) { SubClass s = new SubClass(); s.methodSuper(); s.methodBase(); } } |
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.

Example of Multilevel Inheritance in Java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | class FirstClass { public void displayFirst() { System.out.println("I am First Class"); } } class SecondClass extends FirstClass { public void displaySecond() { System.out.println("I am Second Class"); } } class ThirdClass extends SecondClass { public void displayThird() { System.out.println("I am Third Class"); } } public class Main { public static void main(String[] args) { ThirdClass three = new ThirdClass(); three.displayFirst(); three.displaySecond(); three.displayThird(); } } |
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.

Example of Hierarchical Inheritance in Java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | class Animal { void Dog() { System.out.println("I am dog");} } class Cat extends Animal { void sleep() { System.out.println("I am Cat and I sleep"); } } class Horse extends Animal { void run() { System.out.println("I am Horse and I run"); } } public class Main { public static void main(String args[]) { Horse h=new Horse(); h.Dog(); h.run(); Cat c=new Cat(); c.Dog(); c.sleep(); } } |
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:
