programs of multiple Inheritance:
// multiple inheritance #include<iostream> using namespace std; class A{ int a; public: void set_a(int a1){ a=a1; } int get_a(){ return a; } }; class B{ int b; public: void set_b(int b1){ b=b1; } int get_b(){ return b; } }; class C :public A,public B{ // here class A and B is inherited public: int addition(){ return get_a()+get_b(); } }; int main(){ C obj; obj.set_a(10); // ste_a() is the class of A obj.set_b(3); // here set_b() is the class of B cout<<"Addition of a+b= "<<obj.addition(); }
Addition of a+b= 13
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