Hybrid Inheritance in c++ programming


Hybrid Inheritance


Hybrid inheritance —> It is a combination of hierarchical and multiple 
inheritance.

#include<iostream>
using namespace std;
class A{
protected:
int a;
public:
void seta(){
a=5;
}
};
class B: public A{
protected:
int b;
public:
void setb(){
b=15;
}
};
class C: public B{
protected:
int c;
public:
void setc(){
c=2;
}
};
class D{
protected:
int d;
public:
void setd(){
d=2;
}
};
class E: public C, public D{
private:
int sum;
public:
void total(){
sum=a+b+c+d;
cout<<sum;
}
};

int main(){
E ob;
ob.seta();
ob.setb();
ob.setc();
ob.setd();
ob.total();
}

2 comments:

Powered by Blogger.