Different Types of Inheritance in Java

Inheritance is one of the powerful Object Oriented Concept, and improves re usability of the code.

Below are different types of inheritance
1. Single Inheritance or Simple Inheritance
This is simplest form of Inheritance, in which one class inherits members of another class. In Single Inheritance there exists one Base class and one Derived class.

Single Inheritance in Java
Single Inheritance

2. Multilevel Inheritance
In Multilevel inheritance, a Derived class is a Base class for some other class. As shown in below example class B is Derived from class A. And further class C is derived from class B. And class C can further be Base class of some other class, and there can be few more levels. Multilevel Inheritance example
multi level inheritance
multi level inheritance

Having too many Levels may adversely affect performance during run time.

Refer Inheritance in Generic class.

3. Hierarchical Inheritance
In Multilevel Inheritance, there is common Base class for more than one Derived class.
As shown in below picture class A is common Base class to classes B and C. Hierarchical Inheritance example

4. Hybrid Inheritance
Hybrid Inheritance has more than one inheritance. Actually this is combination of Multilevel, Single and Hierarchical Inheritance. Below is Hybrid Inheritance Example

Hybrid Inheritance in Java
Hybrid Inheritance in Java

You may also like to read:
Why multiple inheritance is not supported in Java?

Hierarchical Inheritance

In Hierarchical Inheritance, there is common Base class for more than one derived class. Below is an Example of Hierarchical Inheritance

class A8
{
	public A8(int i)
	{
		System.out.println("A8() constructor:"+i);
	}

	public void show()
	{
		System.out.println("show() in A8");
	}
}

class B8 extends A8
{
	public B8()
	{
		super(0);
		System.out.println("B8() constructor");
	}

	public void met1()
	{
		System.out.println("met1() in B8");
	}
}

class C8 extends A8
{
	public C8()
	{
		super(20);
		System.out.println("C8() constructor");
	}

	public void met2()
	{
		System.out.println("met2() in C8");
	}
}

public class HierarchicalInheritance {
public static void main(String args[])
{
	B8 obj = new B8();
	System.out.println();
	C8 obj1 = new C8();

	obj.show();
	obj.met1();

	obj1.show();
	obj1.met2();
}
}


Output:
A8() constructor:0
B8() constructor

A8() constructor:20
C8() constructor
show() in A8
met1() in B8
show() in A8
met2() in C8

You may also like to read:
Java Multilevel Inheritance
What is final class