< Prev
Next >

Multilevel Inheritance in C++

In our previous article, we introduced you to one of the types of inheritance - multiple inheritance. Today we are going to discuss the another type of inheritance in C++ named - multilevel inheritance. Multilevel inhertance is performed when a class inherits the features of multiple classes(one class at a time).

The class that wants to use the features of another class is called subclass or derived class, whereas the classes whose features are to be used/inherited is referred to as base classes.

What features a subclass inherits from its base class, through inheritance?

Note - Base class members marked with private visibility mode are never inherited.

Syntax of Multilevel Inheritance

To understand the concept of multilevel inheritance, let us take an example. Let us say that we have a class X which is inherited by a class named Y, which is in turn inherited by another class Z and this is a scenario of multilevel inheritance where -

Syntax of multilevel inheritance
class X
//members of top-level-base-class, X

class Y : visibility-mode X
//members of intermediate-base-class, Y 

class Z : visibility-mode Y
//members of final-derived-class, Z

Rules of inheritance -

Depending on the value of visibility-mode, multiple inheritance can be performed in various ways -

Please subscribe our social media channels for notifications, we post a new article everyday.

Decodejava Google+ Page Decodejava Facebook Page  DecodeJava Twitter Page

Coming Next