Site icon Learn C++

Learn C++ Inheritance :: Multilevel Inheritance

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. If a class is derived from another derived class then it is called multilevel inheritance. In other terms, multilevel inheritance method is using a class which has more than one parent class. Multilevel Inheritance differences from the Multiple Inheritance because of it has a previous class in each levels of new class definitions.

Here is a multilevel inheritance example,

[crayon-673fb885d709b618244343/]

For example, if we take lives as a base class then animals are the derived class which has features of animals and then mammals are the also derived class that is derived from sub-class animal which inherit all the features of lives.

[crayon-673fb885d70a3459730789/]

From this example, we prepared a Multilevel Inheritance example below,

[crayon-673fb885d70a7858321480/]

Here all lives has weight, and animals has a type value and mammals has number of legs. We define an elephant object as a mammal, and we are able to reach all properties and methods of mammals, animals derived classes and lives base class.

Get started building powerful apps with C++Builder!

Exit mobile version