-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12inheritance.cpp
More file actions
66 lines (55 loc) · 1.14 KB
/
Copy path12inheritance.cpp
File metadata and controls
66 lines (55 loc) · 1.14 KB
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
#include<iostream>
#include<string>
using namespace std;
class Vehicle {
public:
string brand = "Ford";
void bhoop(){
cout<<"Bhoop Bhoop \n"; //Overriding
}
};
class sportsCar{
public:
string model = "Jaguar";
void bhoop(){
cout<<"Bhoop Bhoop2 \n";}
void sports(){
cout<<"Eracing \n";
}
};
//Derived Class
class EV: public Vehicle{ //Single inheritance
public:
string model = "Bajaj";
void bhoop(){
cout<<"Bhoop Bhoop Bhoop \n"; //Overriding
}
};
class Bike: public EV{ //Multilevel inheritance
public:
string bname ="Torq";
void bhoop(){
cout<<"Bhoop Bhoop3 \n";} //Overriding
Bike(){
cout << bname <<endl;
}
};
class event:public Vehicle, public sportsCar{ //Multiple inheritance
public:
string eventname ="Racing event \n";
void bhoop(){
cout<<"Bhoop Bhoop4 \n";} //Overriding
event(){
cout<<eventname;
}
};
int main(){
EV myEV;
myEV.bhoop();
cout<<myEV.brand + " " + myEV.model<<endl;
Bike myBike;
myBike.bhoop();
event myevent;
myevent.bhoop();
return 0;
}