File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ // C++ program to demonstrate Multiple Inheritance
2
+
3
+ // Multiple Inheritance - It is defined as the inheritance in which a derived class is inherited
4
+ // from two or more base classes.
5
+
6
+ #include < bits/stdc++.h>
7
+ using namespace std ;
8
+
9
+ // base class 1
10
+ class TerrestrialAnimals {
11
+ public:
12
+ void walk (){
13
+ cout<<" I can walk on land!" <<endl;
14
+ }
15
+ };
16
+
17
+ // base class 2
18
+ class Birds {
19
+ public:
20
+ void fly (){
21
+ cout<<" I can fly!" <<endl;
22
+ }
23
+ };
24
+
25
+ // base class 3
26
+ class AquaticBirds {
27
+ public:
28
+ void swim (){
29
+ cout<<" I can swim!" <<endl;
30
+ }
31
+ };
32
+
33
+ // derived class
34
+ class Duck :public TerrestrialAnimals ,public Birds ,public AquaticBirds {
35
+ public:
36
+ void introduce (){
37
+ cout<<" I am a Duck." <<endl;
38
+ }
39
+ };
40
+
41
+ int main (){
42
+ // Create object of the Duck class
43
+ Duck d1;
44
+ // Calling member of the derived class
45
+ d1.introduce ();
46
+ // Calling members of the base class
47
+ d1.walk ();
48
+ d1.fly ();
49
+ d1.swim ();
50
+ return 0 ;
51
+ }
You can’t perform that action at this time.
0 commit comments