****************************************************************************************
c++ program that illustrates the role of abstract class in building class hierarchy
****************************************************************************************
Program : To write a c++ program that illustrates the role of abstract class in building class hierarchy
Source code :
========
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | </p> <p style="text-align: left;"> #include<iostream.h> #include<conio.h> class A { public: int x; virtual void show()=0; }; class B: public A { public: int y; B() { cout<<"\nThis is an Abstract class demonstration.\n"; x=10; y=20; } void show() { cout<<"\nX= "<<x; cout<<"\nY= "<<y; } }; class C: public A { public: int z; void show() { z=30; cout<<"\nZ= "<<z; } }; void main() { clrscr(); B obj; C obj1; obj.show(); obj1.show(); getch(); } /*Output:- This is an Abstract class demonstration. X= 10 Y= 20 Z= 30 */</p> <p style="text-align: left;"> |
60 total views, no views today