Simple Inheritance by using parameters in c++

Que-  Make a program by using inheritance and parameters 

 #include<iostream>

using namespace std;



class krishna

{

  protected:

  int a,b;


};

class gaura: public krishna 

{ public:

    

   void getdata ( int x, int y)

   {

    a= x;

    b= y;

    int c;

    c=a+b;

   cout<<"sum of two numbers are :- "<<c;

}

};

int main()

{

   gaura ob;

   

   ob.getdata(5,6);

   return 0;


}

Result:-



Post a Comment

Previous Post Next Post