Write a C++ program using concept of multi-level inheritance.


SUBMITTED BY: Nrupeshsinh

DATE: June 26, 2016, 4:15 a.m.

FORMAT: C++

SIZE: 752 Bytes

HITS: 444

  1. # include<iostream.h>
  2. # include<conio.h>
  3. class A
  4. {
  5. public:
  6. int a;
  7. void show()
  8. {
  9. a=10;
  10. }
  11. };
  12. class B : public A
  13. {
  14. public:
  15. int b;
  16. void show1()
  17. {
  18. b=20;
  19. }
  20. };
  21. class C : public B
  22. {
  23. public:
  24. void show2()
  25. {
  26. cout<<"Sum="<<a+b;
  27. }
  28. };
  29. void main()
  30. {
  31. clrscr();
  32. C obj;
  33. obj.show();
  34. obj.show1();
  35. obj.show2();
  36. getch();
  37. }# include<iostream.h>
  38. # include<conio.h>
  39. class A
  40. {
  41. public:
  42. int a;
  43. void show()
  44. {
  45. a=10;
  46. }
  47. };
  48. class B : public A
  49. {
  50. public:
  51. int b;
  52. void show1()
  53. {
  54. b=20;
  55. }
  56. };
  57. class C : public B
  58. {
  59. public:
  60. void show2()
  61. {
  62. cout<<"Sum="<<a+b;
  63. }
  64. };
  65. void main()
  66. {
  67. clrscr();
  68. C obj;
  69. obj.show();
  70. obj.show1();
  71. obj.show2();
  72. getch();
  73. }

comments powered by Disqus