OOP Java – Inheritance

In Java, Inheritance is one class acquires the property of another class. Inheritance allows to reuse of code, And when a piece of code is already present in the parent class (or Superclass, Base class) then need not be rewritten in the child class. The instance variables and methods of the parent class can be called in the child class.

There are various types of inheritance in java.

Single inheritance

Single inheritance enables a derived class to inherit properties and behaviour from a single parent class. Thus allowing code reusability and adding new features to the existing code.

Single Inheritance

Multiple inheritances

Multiple inheritances enable derived many classes to inherit properties and behaviour from a parent class.

Multiple Inheritance

Multiple inheritances are one of rarely used inheritance type in software development. Because it leads some unwanted complexity when further extending the classes. Because of this reason, Java doesn’t support the Multiple inheritances.

Multilevel inheritance

Multilevel inheritance class refers to when a class extends from another class which extends another class is called Multilevel inheritance.

Multilevel inheritance

Hierarchical inheritance

When multiple classes (Child classes) are inherited from a single class (Parent class) is called Hierarchical inheritance. In other words, more than one child classes have the same parent class then this type of inheritance is known as hierarchical inheritance.

Hierarchical inheritance

Hybrid inheritance

Hybrid inheritance is a combination of multiple inheritance and multilevel inheritance. A class is derived from two classes as in multiple inheritances. Since in Java Multiple Inheritance is not supported directly we can achieve Hybrid inheritance also through Interfaces only.

Hybrid inheritance

Add Comment