For C++
Write a C++ program of an original example of hybrid inheritance.
#include <iostream>
using namespace std;
class A
{
public:
int p;
};
class B : public A
{
public:
B() //constructor to initialize p in base class
A
{
p = 100;
}
};
class C
{
public:
int q;
C() //constructor to initialize q
{
q = 40;
}
};
class D : public B, public C //D is derived from class B and class
C
{
public:
void mul()
{
cout << "Multiply= " << p * q;
}
};
int main()
{
D obj1; //object of derived class D
obj1.mul();
return 0;
} //end of program
Get Answers For Free
Most questions answered within 1 hours.