tampurus

11.2 Multilevel Inheritance

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