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 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.
When a single derived class is created from a single base class then the inheritance is called as single 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.
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.
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.
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.
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.