-
Notifications
You must be signed in to change notification settings - Fork 1
/
Q-41.cpp
62 lines (51 loc) · 1.57 KB
/
Q-41.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
60
61
62
#include<iostream>
using namespace std;
// Parent/Base class Super_A
class Super_A {
public:
void methodSuper_A() {
cout<< "I'm a function() of class Super_A"<< endl;
}
};
// class Derived_B is derived from parent class Super_A (Single-Level Inheritence)
class Derived_B : public Super_A {
public:
void methodDerived_B() {
cout<< "I'm a function() of class Derived_B"<< endl;
}
};
// class Derived_C is derived from parent class Derived_B (Multi-Level Inheritence)
class Derived_C : public Derived_B {
public:
void methodDerived_C() {
cout<< "I'm a function() of class Derived_C"<< endl;
}
};
// class Derived_C and Derived_D is derived from parent class Derived_B (Hierarchical Inheritence)
class Derived_D : public Derived_B {
public:
void methodDerived_D() {
cout<< "I'm a function() of class Derived_D"<< endl;
}
};
// class Derived_E is derived from class Derived_C and Derived_D (Multiple Inheritence)
class Derived_E : public Derived_C, public Derived_D {
public:
void methodDerived_E() {
cout<< "I'm a function() of class Derived_E"<< endl;
}
};
int main() {
Super_A obj_A;
obj_A.methodSuper_A();
Derived_B obj_B;
obj_B.methodSuper_A();
obj_B.methodDerived_B();
Derived_E obj;
// obj.methodSuper_A(); // Ambiguous Super_A::methodSuper_A() because of classes Derived_C & Derived_D
// obj.methodDerived_B(); // Ambiguous Derived_B::methodDerived_B() because of classes Derived_C & Derived_D
obj.methodDerived_C();
obj.methodDerived_D();
obj.methodDerived_E();
return 0;
}