-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultilevel_Inheritance.cpp
49 lines (34 loc) · 1.55 KB
/
Multilevel_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
#include <iostream>
#include <string>
using namespace std;
/*———————————————————————————————————————————————————————————————————————————*/
class BaseClass{ // base class
public:
int a = 1;
int b = 2;
int c = 3;
};
/*———————————————————————————————————————————————————————————————————————————*/
class DerivedClass1 : public BaseClass{ // derived class 1
public:
void function1(){
cout << "Hello ";
}
};
/*———————————————————————————————————————————————————————————————————————————*/
class DerivedClass2 : public DerivedClass1{ // derived class 2
public:
void function2(){
cout << "World";
}
};
/*———————————————————————————————————————————————————————————————————————————*/
int main(){
DerivedClass2 object;
cout << object.a << " ";
cout << object.b << " ";
cout << object.c << " ";
object.function1();
object.function2();
cout << endl;
}