Skip to content

Commit 5f51085

Browse files
committed
Runtime polymorphism
1 parent 3baa616 commit 5f51085

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Polymorphism/RuntimePolymorphism.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
class Base
5+
{
6+
public:
7+
void display()
8+
{
9+
cout << "\nDisplay Base";
10+
}
11+
12+
virtual void show()
13+
{
14+
cout << "\nShow Base";
15+
}
16+
};
17+
18+
class Derived : public Base
19+
{
20+
public:
21+
void display()
22+
{
23+
cout << "\nDisplay derived";
24+
}
25+
26+
void show()
27+
{
28+
cout << "\nShow derived";
29+
}
30+
};
31+
32+
int main()
33+
{
34+
Base B;
35+
Derived D;
36+
Base *bptr;
37+
cout << "bptr points to base";
38+
bptr = &B;
39+
bptr->display();
40+
bptr->show();
41+
cout << "\nbptr points to derived";
42+
bptr = &D;
43+
bptr->display();
44+
bptr->show();
45+
return 0;
46+
}

Polymorphism/RuntimePolymorphism.exe

44.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)