Question 3
#include<iostream>
using namespace std;
class Test
{
private:
int x;
public:
Test(int x = 0) { this->x = x; }
void change(Test *t) { this = t; }
void print() { cout << \"x = \" << x << endl; }
};
int main()
{
Test obj(5);
Test *ptr = new Test (10);
obj.change(ptr);
obj.print();
return 0;
}
Question 4
#include<iostream>
using namespace std;
class Test
{
private:
int x;
int y;
public:
Test(int x = 0, int y = 0) { this->x = x; this->y = y; }
static void fun1() { cout << \"Inside fun1()\"; }
static void fun2() { cout << \"Inside fun2()\"; this->fun1(); }
};
int main()
{
Test obj;
obj.fun2();
return 0;
}
Question 5
#include<iostream>
using namespace std;
class Test
{
private:
int x;
public:
Test() {x = 0;}
void destroy() { delete this; }
void print() { cout << \"x = \" << x; }
};
int main()
{
Test obj;
obj.destroy();
obj.print();
return 0;
}
There are 5 questions to complete.