Ad Code

Responsive Advertisement

multi level Inheritance in C++.








programs of multi level Inheritance:

// multi level 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 B{
 int c;
 public:
 
 int multi(){
  c=get_a()*get_b();
  return c;
 } 
};

int main(){
 C obj;  // object of class C
 obj.set_a(10);
 obj.set_b(6);
 cout<<"multiply of a*b = "<<obj.multi();
}



out put:
 multiply of a*b = 60



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. 
❮ Previous                                                      Next ❯

Post a Comment

0 Comments