-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10_polymorphism.cpp
75 lines (55 loc) · 1.48 KB
/
10_polymorphism.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<iostream>
using namespace std;
/*
NOTE:
1) Class with pure virtual functions called as (Abstract Class)
2) Object of Abstarct class can't be declared
3) Pointer of Abstract class can be declared that too by using some Derived class memory.
4) Pure Virtual Functions must be implemented inside Derived Classes
5) Purpose of Classes with Pure Virtual functions is Polymorphism and these classes can be called as (Interface)
6) Purpose of Classes with Concrete Functions is Reuseability
*/
class Car { // Abstract Class -> With Only Pure functions can be called as Interface
public:
/*
Don't need Definition of these functions here so make it as Pure Virtual Functions
virtual void start() {
cout << "Car Started" << endl;
}
virtual void stop() {
cout << "Car Stopped" << endl;
}
*/
virtual void start() = 0;
virtual void stop() = 0;
};
class Innova : public Car {
public:
void start() {
cout << "Innova Started" << endl;
}
void stop() {
cout << "Innova Stopped" << endl;
}
};
class Swift : public Car {
public:
void start() {
cout << "Swift Started" << endl;
}
void stop() {
cout << "Swift Stopped" << endl;
}
};
int main() {
// Car *C = new Car;
// C->start();
// C->stop();
Car *IC = new Innova;
IC->start();
IC->stop();
Car *SC = new Swift;
SC->start();
SC->stop();
return 0;
}