A
asit
1 #include <iostream>
2
3 using namespace std;
4
5 class my_class
6 {
7 int a;
8 int b;
9 public:
10 my_class()
11 {
12 a=0;
13 b=0;
14 cout<<"Default constructor"<<endl;
15 }
16 my_class(int x, int y):a(x),b(y)
17 {
18 cout<<"Parameterized constructor called"<<endl;
19 }
20 ~my_class()
21 {
22 cout<<"Destructor called"<<endl;
23 }
24 void put_data()
25 {
26 cout<<a<<" "<<b<<endl;
27 }
28
29 };
30
31 int main()
32 {
33 my_class ob1;
34 my_class ob2(10,20);
35 my_class ob3=my_class(100,300);
36 ob1.put_data();
37 ob2.put_data();
38 ob3.put_data();
39 ob1=my_class(1000,3000);
40 ob1.put_data();
41 return 0;
42 }
In the above program, will the destructor be called at line 39. Will
it be called before parameterized constructor or before ??
2
3 using namespace std;
4
5 class my_class
6 {
7 int a;
8 int b;
9 public:
10 my_class()
11 {
12 a=0;
13 b=0;
14 cout<<"Default constructor"<<endl;
15 }
16 my_class(int x, int y):a(x),b(y)
17 {
18 cout<<"Parameterized constructor called"<<endl;
19 }
20 ~my_class()
21 {
22 cout<<"Destructor called"<<endl;
23 }
24 void put_data()
25 {
26 cout<<a<<" "<<b<<endl;
27 }
28
29 };
30
31 int main()
32 {
33 my_class ob1;
34 my_class ob2(10,20);
35 my_class ob3=my_class(100,300);
36 ob1.put_data();
37 ob2.put_data();
38 ob3.put_data();
39 ob1=my_class(1000,3000);
40 ob1.put_data();
41 return 0;
42 }
In the above program, will the destructor be called at line 39. Will
it be called before parameterized constructor or before ??