In multiple inheritance, more than one base classes are derived from one sub class. Hence a class can inherit characteristics and features from more than one parent class.

Block Diagram of Multiple inheritance in C++

Very few languages support multiple inheritance. C++ is one of them.

Syntax of Multiple inheritance in C++

Note: Constructors are executed in the same order in which their’s class has been inherited. For e.g in above syntax, Base1 class constructor will be called first then Base2 class constructor.

Example of Multiple Inheritance in C++

Output of Program

Multiple Inheritance example in C++

Notice we haven’t declared x and y in Derive class still, our program had run without any error because, in our C++ program, we have inherited Base1 and Base2 class into Derive class, therefore we are able to use x of Base1 and y of Base2 in Derive to calculate z.

If you have any doubt’s or didn’t understand any part of the program then do comment below.

Leave a Reply

6 + 18 =