Multiple inheritances in C++ is easy to understand, there will be many base classes and there is only one derived class that derives from all the base classes. The following is the schematic representation.

Base1 and Base2 are the base classes and class Child is the derived class. Only one class is derived from both the base classes.

Have a look at the following example Here as you can see in the schematic representation, Base1 and Base2 are the base classes and the Child is derived class.

Program

#include <iostream>
using namespace std;
 
class Base1 {
  public:
    Base1()
    {
      cout << "This is Base 1" << endl;
    }
};
 
class Base2 {
  public:
    Base2()
    {
      cout << "This is Base 2" << endl;
    }
};
 
class Child: public Base1, public Base2 {
 
};
 
int main()
{
    Child obj;
    return 0;
}

Output:-
This is Base 1
This is Base 2

Explanation of the program

In this example, we can make out that the Class M and Class N are the base classes and class p is the derived class of both these classes. This is called as multiple inheritance.

This article is written by our awesome writer
Comments to: Simple Program for Multiple Inheritance in C++

Your email address will not be published. Required fields are marked *

Attach images - Only PNG, JPG, JPEG and GIF are supported.

New Dark Mode Is Here

Sign In to access the new Dark Mode reading option.

Join our Newsletter

Get our monthly recap with the latest news, articles and resources.

By subscribing you agree to our Privacy Policy.

Latest Articles

Explore Tutorials By Categories

About

Codeverb is simply an all in one interactive learning portal, we regularly add new topics and keep improving the existing ones, if you have any suggestions, questions, bugs issue or any other queries you can simply reach us via the contact page

Login

Welcome to Codeverb

Ready to learn something new?
Join Codeverb!

Read Smart, Save Time
  •  
    Strength indicator
  •  
  •  
    Log In | Lost Password