Quantcast
Channel: Java Question Bank » Cpp Programs
Viewing all articles
Browse latest Browse all 22

c++ program that illustrates the role of abstract class in building class hierarchy

$
0
0

****************************************************************************************

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&lt;iostream.h&gt;
#include&lt;conio.h&gt;
class A
{
public:
int x;
virtual void show()=0;
};
class B: public A
{
public:
int y;
B()
{
cout&lt;&lt;"\nThis is an Abstract class demonstration.\n";
x=10;
y=20;
}
void show()
{
cout&lt;&lt;"\nX= "&lt;&lt;x;
cout&lt;&lt;"\nY= "&lt;&lt;y;
}
};
class C: public A
{
public:
int z;
void show()
{
z=30;
cout&lt;&lt;"\nZ= "&lt;&lt;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


Viewing all articles
Browse latest Browse all 22

Trending Articles