Answer to Question #327230 in C++ for Vaibhav

Question #327230

Write a programme to demonstrate Hybrid Inheritance with some real examples. Also mention the possible ways of removing ambiguity in this Inheritance.



1
Expert's answer
2022-04-11T12:13:07-0400
#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;
} 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS