-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path28_multiple_inheritance.cpp
More file actions
71 lines (67 loc) · 1.53 KB
/
Copy path28_multiple_inheritance.cpp
File metadata and controls
71 lines (67 loc) · 1.53 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
67
68
69
70
71
//example on multiple inheritance
#include <iostream>
using namespace std;
//base-class 1
class engineer
{
public :
string branch;
engineer() //default constructor
{
cout<<"Base-class 1 is called"<<endl;
}
void work()
{
cout<<"My Branch is "<<branch<<endl;
}
};
//base-class 2
class youtuber
{
public:
int subscribers;
youtuber() //default constructor
{
cout<<"Base-class 2 is called"<<endl;
}
void contentcreator()
{
cout<<"Total Subscribers : "<<subscribers<<endl;
}
};
//derived class (multiple inheritance)
class teacher : public engineer,public youtuber
{
public:
string name;
teacher() //default constructor
{
cout<<"Derived class called"<<endl;
}
//creating constructor
teacher(string name,string branch,int subscribers)
{
this->name=name;
this->branch=branch;
this->subscribers=subscribers;
}
void showcase()
{
cout<<"My name is "<<name<<endl;
work();
contentcreator();
}
};
int main()
{
teacher A2;
teacher A1("Piyush","CSE",100000);
A1.showcase();
return 0;
}
/*
->>>> class teacher : public engineer, public youtuber
The compiler will always initialize engineer first,
youtuber second, and then finally execute the teacher constructor body.
If you were to swap them to public youtuber, public engineer, the execution order would instantly reverse!
*/