Skip to content

Commit c54b11f

Browse files
committed
2 parents 26ed959 + 19aa228 commit c54b11f

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

0 commit comments

Comments
 (0)