Site icon Learn C++

Learn C++ Inheritance :: Hierarchical Inheritance

Let’s remember that, Object Oriented Programming (OOP) is a way to integrate with objects which can contain data in the form (attributes or properties of objects), and code blocks in the form of procedures (methodsfunctions of objects). These attributes and methods are variables and functions that belong to the class, they are generally referred to as class members. In C++, classes have members (attributesmethods) and we should protect each member inside this class.

The Inheritance is one of the most important concept in object-oriented C++ programming as in other features of Classes. Inheritance allows us to define a class in terms of another class, and it makes easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time. Inheritance implements the relationship between classes. For example, a rectangle is a kind of shape and ellipse is a kind of shape etc.

Multiple Inheritance is another feature of C++ that a class can inherit from more than one classes. For example a derived class can be inherited from more than one base classes or derived classes.

In Hierarchical Inheritance another type of Inheritance, more than one sub class is inherited from a single base class. i.e. more than one derived class is created from a single base class.

Simply we can define more than one classes which are inherited from same base;

[crayon-673fb84d51ffc036707737/]

A simple Hierarchical Inheritance example is given as below,

[crayon-673fb84d52007576390575/]

Here both Mammal and Bird inherited from the base live class. As in this example we can create more complex tree branched class types by using Hierarchical Inheritance.

Get started building powerful apps with C++Builder!

Exit mobile version