-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance2.cpp
More file actions
44 lines (31 loc) · 786 Bytes
/
inheritance2.cpp
File metadata and controls
44 lines (31 loc) · 786 Bytes
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
#include <iostream>
using namespace std;
// Single Inheritance
class Base {
public:
void func() {
cout << "Base class function." << endl;
}
};
class DerivedSingle : public Base { };
// Multiple Inheritance
class DerivedMultiple : public DerivedSingle, public Base { };
// Multilevel Inheritance
class DerivedMultiLevel1 : public Base { };
class DerivedMultiLevel2 : public DerivedMultiLevel1 { };
// Hierarchical Inheritance
class DerivedHierarchical1 : public Base { };
class DerivedHierarchical2 : public Base { };
int main() {
DerivedSingle ds;
ds.func();
DerivedMultiple dm;
dm.func();
DerivedMultiLevel2 dml;
dml.func();
DerivedHierarchical1 dh1;
dh1.func();
DerivedHierarchical2 dh2;
dh2.func();
return 0;
}