C++ Program using multiple inheritance
In this program, You will learn how to implement multiple inheritance in C++.
class A {
//statement
}
class B {
//statement
}
class C : public A, public B {
//statement
}
Example: How to implement multiple inheritance in C++.
#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 << "value of x is:" << x;
cout << "\nvalue of y is:" << y;
}
};
int main() {
C obj;
obj.display();
return 0;
}
Output:
value of x is:10
value of y is:20