AbdulFathaah

Single Inheritance

Mar 11th, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include<conio.h>
  2. #include<iostream>
  3. using namespace std;
  4. class Base1
  5. {
  6. protected :int a;
  7. public :void geta();
  8. };
  9. class Derive :public Base1
  10. {
  11. private :int b;
  12. public :void getb();
  13. void display();
  14. };
  15. void Base1 ::geta()
  16. {
  17. cout<<"Enter value for A:";
  18. cin>>a;
  19. }
  20. void Derive ::getb()
  21. {
  22. cout<<"Enter value for B:";
  23. cin>>b;
  24. }
  25. void Derive ::display()
  26. {
  27. cout<<"A = "<<a<<endl;
  28. cout<<"B = "<<b<<endl;
  29.  
  30. }
  31. int main()
  32. {
  33. Derive obj;
  34. obj.geta();
  35. obj.getb();
  36. obj.display();
  37. getch();
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment