-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathollie157_Inheritance.cpp
59 lines (43 loc) · 1021 Bytes
/
ollie157_Inheritance.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
#include<bits/stdc++.h>
using namespace std;
// Availability vs Accessibility and Visibility modes
// Inheritance establishes a "is-a" relationship between the Derived and the Base class
// "is-a" relationship can only be implemented via public inheritance
// "is-a" relationship states that the public attributes and methods of the base class should also be publicly available to the
// derived class. Therefore, it can only be implemented via public inheritance.
class Car
{
private:
int gear = 0;
protected:
void getGearValue()
{
cout << "The vehicle is currently in gear " << this -> gear << endl;
}
public:
void incrementGear()
{
if(gear < 5)
{
gear++;
}
}
};
class SportsCar : public Car
{
public:
void currentGear()
{
getGearValue();
}
};
int main()
{
cout << endl;
SportsCar sc;
sc.currentGear();
sc.incrementGear();
sc.currentGear();
cout << endl;
return 0;
}