AbdulFathaah

Multiple Inheritance

Mar 11th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 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 Base2
  10. {
  11. protected :int b;
  12. public :void getb();
  13. };
  14. class Derive :public Base1,public Base2
  15. {
  16. private :int c;
  17. public :void getc();
  18. void display();
  19. };
  20. void Base1 ::geta()
  21. {
  22. cout<<"Enter value for A:";
  23. cin>>a;
  24. }
  25. void Base2 ::getb()
  26. {
  27. cout<<"Enter value for B:";
  28. cin>>b;
  29. }
  30. void Derive ::getc()
  31. {
  32. cout<<"Enter value for C:";
  33. cin>>c;
  34. }
  35. void Derive ::display()
  36. {
  37. cout<<"A = "<<a<<endl;
  38. cout<<"B = "<<b<<endl;
  39. cout<<"C = "<<c<<endl;
  40.  
  41. }
  42. int main()
  43. {
  44. Derive obj;
  45. obj.geta();
  46. obj.getb();
  47. obj.getc();
  48. obj.display();
  49. getch();
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment