#include<iostream>
using namespace std;
class test
{
private:
int x;
int y;
public:
test(int a=0,int b=0)
{
this->x=a;
this->y=b;
}
test& putx(int a)
{
this->x=a;
return *this;
}
test& puty(int b)
{
this->y=b;
return *this;
}
void print()
{
cout<<"x="<<x<<endl<<"y="<<y<<endl;
}
};
int main()
{
test obj1(10,20),obj2(30,40);
obj1.print();
obj1.putx(11);
obj2.puty(251);
obj2.print();
obj1.print();
return 0;
}
Note: Need to be arranged in compiler after copied
OutPut:
x=10
y=20
x=30
y=251
x=11
y=20
y=20
x=30
y=251
x=11
y=20