Wednesday, April 6, 2016

Multiple Inheritance in C++

Inheritance in which a derived class is derived from several base class is known asmultiple inheritance.
A class can inherit the attributes of two or more classes as shown in fig. below. This is known as multiple inheritance.
Multiple Inheritance in C++
Multiple inheritance allows us to combine the features of several existing classes as a starting point for defining new classes. It is like a child inheriting the physical features of one parent and the intelligence of another.
The syntax of a derived class with multiple base class is as follows:
where visibility may be either public or private.
The base classes are separated by commas.
Example:
Classes M and N have been specified as follows:
The derived class P, as declared above would, in effect, contain all the members of M and N in addition to its own members as shown below:
The main() function of the program based on the above defined class P may be written as follows:

0 comments:

Post a Comment