8000 Virtual Keyword · DhirajGadekar/Cpp_programming@28ef940 · GitHub
[go: up one dir, main page]

Skip to co 8000 ntent

Commit 28ef940

Browse files
committed
Virtual Keyword
1 parent 2be57dd commit 28ef940

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Polymorphism/1_VirtualKeyWord.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include<iostream>
2+
3+
class Parent {
4+
5+
public:
6+
Parent() {
7+
8+
std::cout << "Parent Constructor" << std::endl;
9+
}
10+
11+
virtual void getData() {
12+
13+
std::cout << "Parent getData" << std::endl;
14+
}
15+
};
16+
17+
class Child : public Parent {
18+
19+
public:
20+
Child() {
21+
22+
std::cout << "Child Constructor" << std::endl;
23+
}
24+
25+
void getData() { //implicitely virtual comes here .......
26+
27+
std::cout << "Child getData" << std::endl;
28+
}
29+
};
30+
31+
int main() {
32+
33+
Parent *obj = new Child();
34+
obj->getData();
35+
36+
return 0;
37+
}

0 commit comments

Comments
 (0)
0