Complete Guide on Inheritance in Java – Object Oriented Programing

In Object Oriented Programming scheme, Inheritance is all about Properties and Behaviour sharing between two or multiple Objects. When any class inherits all the properties and behavior of any class, called Derived class or Child class and whose properties and behaviors are inherited, called Parent class or Superclass.

Inheritance is a Mechanism where one Object acquires the properties and behaviour of other Object.

This represents IS-A relationship, also knoiwn as parent-child relationship.

types-of-inheritanceThis can be multiple types, are as follows:

1. Single :

When child class extending only one class and the parent class does not extend any other class, called Single Inheritance. This is completely supported by Java.

2. Multiple :

When child class extending more than one class then Its called Multiple Inheritance.

Java does not support Multiple inheritances. We can not extend more than one class in Java it will be a compile-time error.

The interface in Java, supports Multiple Inheritances. We can extends more than one Interface to child interface.

3. Multi-level :

When Child class extends any other class which is already Inherits the property of any other class, called Multilevel inheritance occurred.

4. Hierarchical :

When two or more classes inherit one parent class, called hierarchical inheritance occurred.

5. Hybrid :

when any class extends multiple classes which are already the inheriting property of any other class, called Hybrid inheritance occurred.

This kind of inheritance is also not supported by Java or May depend on your cases.

For More Details watch the video:

Purpose to use:
  • Code-Reuse:  This mechanism whereby a subclass re-use code in a base class. By default, the subclass retains all of the operations of the base class, but the subclass may override some or all operations, replacing the base-class implementation with its own.
  • Achieve Polymorphism

Complex inheritance, or used within an insufficiently mature design may lead to the yo-yo problem.

I’m Dipendra, software developer, and designer who has written code in many of the language known to mankind.Passionate about Technology. In my free time, I love to write articles and build the code.

Leave a reply:

Your email address will not be published.

Site Footer