In this program, class B is derived from A and C is derived from B. An object of class C is defined in main() function. When the display() function is called, display() in class A is executed because there is no display() function in C and B. The program first looks for display() in class C first but, can't find it. Then, looks in B because C is derived from B. Again it can't find it. And finally looks it in A and executes the codes inside that function.

Note: This program is intended to give you idea on how multiple inheritance works rather than the condition in which multiple inheritance is used.

Ambiguity in Multiple Inheritance

Multiple inheritance may be helpful in certain cases but, sometimes odd sort of problem encounters while using multiple inheritance. For example: Two base classes have functions with same name which is not overridden in derived class and if you write code to access that function using object of derived class, compiler shows error because, it cannot determine which function to call. Here is a code for this type of ambiguity in multiple inheritance

Hierarchical Inhertiance

If more than one class is inherited from a base class, it's known as hierarchical inheritance. In general, all features that are common in child classes are included in base class in hierarchical inheritance. For example: Physics, Chemistry, Biology are derived from Science class.