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

C++ program to illustrates how run time polymorphism is achieved using virtual functions

$
0
0

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

Program : To write a C++ program to illustrates how run time polymorphism is achieved using virtual functions

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

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
#include<iostream.h>
#include<conio.h>

class A
{
int x;
public:
void read()
{
cout<<"\n Enter X value:";
cin>>x;
}
virtual void show()
{
cout<<"\n X="<<x;
}
};
class B:public A
{
int y;
public:
void input()
{
read();
cout<<"\n Enter Y value:";
cin>>y;
}
virtual void show()
{
cout<<"\n Y="<<y;
}
};
void main()
{
B obj;
clrscr();
obj.input();
obj.A::show();
obj.show();
getch();
}

/*--------------------INPUT/OUTPUT---------------

Enter X value:30

Enter Y value:40

X=30
Y=40
------------------------------------------------*/

19 total views, 1 views today


Viewing all articles
Browse latest Browse all 22

Trending Articles