Skip to content

Commit 48b30ea

Browse files
committed
order of execution of constructurs and destructors in inheritence
1 parent 3a98210 commit 48b30ea

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include<iostream>
2+
3+
using namespace std;
4+
5+
class Person {
6+
public :
7+
Person() {
8+
cout<<"Constructor of base class"<<endl;
9+
}
10+
~Person() {
11+
cout<<"Destructor of Base class"<<endl;
12+
}
13+
14+
};
15+
16+
17+
class Student : public Person {
18+
public:
19+
Student() {
20+
cout<<"Constructor of derived class"<<endl;
21+
}
22+
~Student() {
23+
cout<<"Destructor of derived class"<<endl;
24+
}
25+
26+
};
27+
28+
29+
int main() {
30+
31+
Student s;//object created-constructor called
32+
33+
34+
return 0;
35+
36+
}

publicInheritence.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ using namespace std;
55

66
class Shape {
77

8-
protected:
9-
8+
109

1110
public:
1211
int side;

0 commit comments

Comments
 (0)