Facebook
From Utsha, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 199
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class base
  5. {
  6.     double x;
  7.  
  8. public:
  9.     void setx(double i)
  10.     {
  11.         x=i;
  12.     }
  13.  
  14.     void showx()
  15.     {
  16.         cout<<"X = "<<x<<endl;
  17.     }
  18. };
  19.  
  20. class derived :public base
  21. {
  22.     double y;
  23.  
  24. public:
  25.     void sety(double i)
  26.     {
  27.         y=i;
  28.     }
  29.     void showy()
  30.     {
  31.         cout<<"Y = "<<y<<endl;
  32.     }
  33. };
  34.  
  35.  
  36. int main()
  37. {
  38.     derived obj;
  39.  
  40.     obj.setx(10);
  41.     obj.sety(20);
  42.  
  43.     obj.showx();
  44.     obj.showy();
  45.    
  46.     return 0;
  47. }
  48.