C-- Multiple Inheritance (1)
C-- Multiple Inheritance (1)
It allows us to create a new class (derived class) from an existing class (base
class).
The derived class inherits the features from the base class and can have
additional features of its own.
is-a relationship
Inheritance is an is-a relationship. We use inheritance only if an is-a
relationship is present between the two classes.
● A car is a vehicle.
● Orange is a fruit.
● A surgeon is a doctor.
● A dog is an animal.
In C++ programming, a class can be derived from more than one parent. For example, A class
Bat is derived from base classes Mammal and WingedAnimal. It makes sense because bat is a
mammal as well as a winged animal.
● Code :
Develop a C++ microproject to print college information using multiple inheritance
(1)College name
(2)no.of branches
(3) no. Of students in each branch
OUTPUT:-
In this example, we have three base classes: CollegeName, NumberOfBranches, and
NumberOfStudents. The CollegeInformation class is derived from these three base classes using
multiple inheritance. You can create an instance of CollegeInformation and set the college name,
number of branches, and the number of students in each branch, and then display the college
The most obvious problem with multiple inheritance occurs during function
overriding.
Suppose, two base classes have a same function which is not overridden in
derived class.
If you try to call the function using the object of the derived class, compiler
shows error. It's because compiler doesn't know which function to call.