-
Notifications
You must be signed in to change notification settings - Fork 7
/
abstractClass.cpp
41 lines (35 loc) · 973 Bytes
/
abstractClass.cpp
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
#include<bits/stdc++.h>
using namespace std;
// Abstract Class
class Person {
public:
/*
Virtual keyword is necessary because without this keyword, early binding of
print() function occurs and hence base class function can be called using object
pointers
*/
virtual void print() = 0;
};
/*
For the inherited class, either we can override the pure virtual function of base class
or declare the function as pure virtual in child class also.
One of the two has to be done for sure
*/
class Student: public Person {
public:
void print() {
cout << "In Student Class\n";
}
};
int main() {
/*
Pure Virtual Function
--> A do nothing function is called Pure Virtual Function
Abstract Class
--> Any class which has one or more pure virtual functions is called Abstract class
--> One cannot create an object of Abstract class (can't instanciate it)
*/
// Person p; // This is CE
Student s;
s.print();
}