Inheritance is the capability of one class of things to derive its properties from another class of things. It is an essential object-oriented programming concept.

Let’s think of inheritance from a real-life perspective – take, for example, your family. You derive some of your characteristics from your father and some from your mother. Some of these characteristics are salient, while some are prominent like the color of your hair or eyes. Even further, your father and mother derive their characteristics from their parents.

Now, how exactly does this translate into code?

Well, we have all sorts of real-world relations that inheritance can describe in programming such that some features are salient while others are visible to the user clearly. This is implemented through inheritance, having different access levels (private, public and protected).

Let’s consider another example to understand this better –  a class called ‘Shape’ defines the basic form of shapes like circles, triangles, and squares. Thus, classes ‘Circle’, ‘Triangle’  and ‘Square’ inherit from ‘Shape’ and add onto the basic structure on the basis of their individual features i.e. the specific areas, perimeters, etc of the particular shapes. Similarly, ‘Equilateral Triangle’, ‘Isosceles Triangle’ etc become derived classes from ‘Triangle’ with the specific where the definition for the sides changes accordingly.

Types of inheritance:

  • Single Inheritance
  • Multiple Inheritance
  • Multilevel Inheritance
  • Hierarchical Inheritance
  • Hybrid Inheritance
Types of Inheritance
Types of Inheritance

Inheritance has several advantages as follows: reusability, real-world relevance; time-saving; transitive nature; easier debugging.

6 Replies to “Inheritance”

  1. where a subclass is inherited from another subclass. It is not uncommon that a class is derived from another derived class as shown in the figure “Multilevel inheritance”. Perfect depiction

  2. Simply wish to say your article is as amazing.
    The clarity in your put up is just spectacular!!

    Thanks a million and please carry on the enjoyable work.

  3. Superb site you have here but I was curious if you knew of any discussion boards that cover the same topics talked about in this article? If you have any recommendations, please let me know. Bless you!

Leave a Reply

Your email address will not be published. Required fields are marked *