programs of hybrid inheritance :
// Hybrid inheritence #include<iostream> using namespace std; class A{ int a; public: void set_a(int a1){ a=a1; } int get_a(){ return a; } }; class B:public A{ int b; public: void set_b(int b1){ b=b1; } int get_b(){ return b; } }; class C: public A{ int c; public: void set_c(int c1){ c=c1; } void addition(){ cout<<"\n\n addition only class A and class C "<<c+get_a(); } }; class D: public B{ public: void addition(){ cout<<"\n\n Addition of class A and class B in class D : "<<get_a()+get_b(); } }; int main(){ D obj; obj.set_a(5); obj.set_b(10); obj.addition(); C obj2; obj2.set_a(20); obj2.set_c(10); obj2.addition(); }
Addition of class A and class B in class D : 15 Addition only class A and class C : 30
If you like code with vibhu and would like to contribute, you can also write an article using This link :
https://docs.google.com/forms/d/e/1FAIpQLScAmvlPvNUz35R-G0nc_zpRVP3o8xlhtFgC3aKPyLetX_RyXg/viewform?pli=1
OR mail your article to codewithvibhu@gmail.com. See your article appearing on the code with vibhu main page and help other students.
0 Comments