-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConst_Dest.cpp
More file actions
63 lines (55 loc) · 1018 Bytes
/
Copy pathConst_Dest.cpp
File metadata and controls
63 lines (55 loc) · 1018 Bytes
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
63
//constructor and destructor in inheritance
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
class A
{
private:
int a;
public:
//this is constructor
A(int x)
{
a = x;
cout<<"Class A"<<endl;
}
//default constructor
A()
{
}
//Destructor
~A()
{
cout<<"Destructor of class A"<<endl;
}
};
// class A is inherited by class B
class B:public A
{
private:
int b;
//this is constructor inheritance
public:
B(int x,int y):A(x) //first class B constructor calling class A constructor
{
b = y;
cout<<"Class B"<<endl;
}
//default constructor
B()
{
}
//Destructor : before end of execution of obj
~B()
{
cout<<"Destructor of class B"<<endl;
}
};
int main(int argc, char const *argv[])
{
system("cls");
B b1(10,20); //constructor implicitly invoked when object is created
system("pause");
return 0;
}