tampurus

11.1 Single Inheritance

Jan 6th, 2022
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class Base{
  4. private:
  5.     int x;
  6. public:
  7.     void read_data(){
  8.         cout<<"Enter number"<<endl;
  9.         cin>>x;
  10.     }
  11.     int getx() {return x;}
  12. };
  13. class Derived: public Base{
  14. private:
  15.     int y;
  16. public:
  17.     void get_data(){
  18.         cout<<"Enter number"<<endl;
  19.         cin>>y;
  20.     }
  21.     int product(){
  22.         return getx()*y;
  23.     }
  24. };
  25.  
  26. int main()
  27. {
  28.     Derived obj;
  29.     obj.read_data();
  30.     obj.get_data();
  31.     cout<<"product is" <<obj.product();
  32.     return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment