Sunday, 25 April 2021

Hierarchical Inheritance in C++

 #include<iostream.h>

#include<conio.h>

class A

{

public:

int a,b;


};

class B:A

{

public:

B()

{

a=5;

b=10;

cout<<a+b<<endl;

}

};

class C:A

{

public:

void show()

{

a=2;

b=3;

cout<<a+b<<endl;


}


};


int main()

{

clrscr();

B ob;

C ob1;

ob1.show();

getch();

return 0;


}

No comments:

Post a Comment