Write a programme to demonstrate Hybrid Inheritance with some real examples. Also mention the possible ways of removing ambiguity in this Inheritance.
#include <iostream>
using namespace std;
class A
{
public:
int x;
};
class B : public A
{
public:
B()
{
x = 10;
}
};
class C
{
public:
int y;
C()
{
y = 4;
}
};
class D : public B, public C
{
public:
void sum()
{
cout << "Sum= " << x + y;
}
};
int main()
{
D obj1;
obj1.sum();
return 0;
}
Comments
Leave a comment