C++ Program using multiple inheritance


In this program, You will learn how to implement multiple inheritance in C++.


class A { }

class B { }

class C : public A, public B { }


Example: How to implement multiple inheritance in C++

Run it Now
#include<iostream>
using namespace std;

class A {
public:
   int x;

   A() {
       x = 10;
   }
};

class B {

public:
    int y;

   B() {
       y = 20;
   }
};

class C : public A, public B {
public:

   void display() {
       cout << "The value of x is :" << x;
       cout << "\nThe value of y is :" << y;
   }
};

int main() {

   C obj;
   obj.display();

   return 0;
}

Output:

The value of x is :10
The value of y is :20