What are different types of Inheritances?

There are five types inheritances--

  • Single Inheritance
  • Hierarchical Inheritance
  • Multi-Level Inheritance
  • Hybrid Inheritance
  • Multiple Inheritance
    Let us discuss them one by one.

Single inheritance
Single inheritance is the simplest form of inheritance. When a class extends another one class only then we call it a single inheritance. The below flow diagram shows that class B extends only one class which is A. Here A is a parent class of B and B would be a child class of A.
0_1499518268367_72db9d7c-0d0f-47ab-b5b6-2e1ba194b92d-image.png
When a single derived class is created from a single base class then the inheritance is called as single inheritance.

Hierarchical Inheritance
When more than one derived class are created from a single base class, then that inheritance is called as hierarchical inheritance. In such kind of inheritance one class is inherited by many sub classes. In the example, class B, C and D inherits the same class A. A is parent class (or base class) of B, C and D.
0_1499518353650_85384487-8a31-4bc0-967c-fbcf5d0b7d2e-image.png

Multi-Level Inheritance
When a derived class is created from another derived class, then that inheritance is called as multi level inheritance. Multilevel inheritance refers to a mechanism in object oriented technology where one can inherit from a derived class, thereby making this derived class the base class for the new class. As you can see in figure C is subclass or child class of B and B is a child class of A.
0_1499518462767_f8984933-71a4-4265-92ec-e5b251e03c89-image.png

Hybrid Inheritance
Any combination of single, hierarchical and multi level inheritances is called as hybrid inheritance. In simple terms we can say that Hybrid inheritance is a combination of Single and Multiple inheritance. A hybrid inheritance can be achieved in the Java using interfaces.
0_1499518536979_3ab7f944-6e39-466a-a566-9322af528d6d-image.png

Multiple Inheritance
When a derived class is created from more than one base class then that inheritance is called as multiple inheritance. But multiple inheritance is not supported by Java using classes and can be done using interfaces.
0_1499518601432_50d1aebb-6e1c-4d5c-8e0c-289693c5fe6f-image.png
Handling the complexity that causes due to multiple inheritance is very complex. Hence it was not supported in Java with class and it can be done with interfaces.

Comments (0)