programs of Single inheritance :
// simple level inheritence #include<iostream> using namespace std; class A{ // parent class int a; // a is a veriable public: // access modigier void set_a(int a1){ // setter method a=a1; // set the value of a } int get_a(){ return a; } }; class B :public A{ // inherite the class A into class B int b; public: void set_b(int b1){ b=b1; } int multi(){ return b*get_a(); // get_a() is the method of class A } }; int main(){ B obj; // obj is the object of class B obj.set_a(10); // here the obj is access the method of class A obj.set_b(5); // here set the value of class B veriable b cout<<"multiply of a and b is a*b= "<<obj.multi(); // return the value of b*a }
multiply of a and b is a*b= 50
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