Hierarchical Inheritance in c++ Example






Hierarchical Inheritance in c++ Example
  GNU nano 2.9.1                                                                     test.cpp                                                                      Modified  
/**************************************************************************************
******************************Designed and Developed by V2Geeks******************************************
********************************************************************************************************/
 // Example of  Hierarchical Inheritance (A->B and A->C)
 #include<iostream.h>
 #include<conio.h>
 class A                // base class
 {
public:
        void display()
        {
        cout<<"Hello from A \n";
        }
 };
 class B : public A // now B is child of  A
 {
        // now class B have display method of it's parent class A
 };
 class C : public A // now C is also child of  A
 {
 // now C have display method of it's parent class A
 };

 void main()
        {
        B objB;   //object of  class B
        C objC;   //object of  class C
        clrscr();
        objB.display();
        objC.display();
getch();
 }
Reactions: