Skip to content

Commit ceb0ea9

Browse files
committed
implemented multiple inheritence and calling base class constructor in child class
1 parent 48b30ea commit ceb0ea9

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

multipleInheritence.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include<iostream>
2+
3+
using namespace std;
4+
5+
class father {
6+
public:
7+
int height;
8+
father(int h) {
9+
height = h ;
10+
cout<<"Father constructor called"<<endl;
11+
12+
}
13+
14+
void getHt() {
15+
cout<<"Height is "<<height<<endl;
16+
}
17+
18+
19+
20+
21+
};
22+
23+
class mother {
24+
public :
25+
string skincolor;
26+
mother(string iscolor) {
27+
28+
skincolor = iscolor;
29+
cout<<"Mother constructor called"<<endl;
30+
}
31+
32+
void getColor() {
33+
cout<<"Skin color is "<< skincolor<<endl;
34+
}
35+
36+
37+
};
38+
39+
40+
//multiple inheritence
41+
class child: public father, public mother {
42+
43+
public :
44+
//calling parent class constructors and passing arguments to them
45+
child(int ht,string color) : father(ht) , mother(color) {
46+
cout<<"Child constructor called"<<endl;
47+
48+
}
49+
50+
};
51+
52+
53+
int main () {
54+
55+
child c(172,"white");
56+
c.getColor();
57+
c.getHt();
58+
59+
60+
61+
return 0;
62+
}

0 commit comments

Comments
 (0)