Object Assignment
If
want one object to second object we have to assign then we have to use
assignment operator.
If
want one object to second object assign the value then we have to create two
object.
If
first object value is a1 then second object value is a2 then the value of a1 and the value of a2 will assign in object.
Example:
a2=a1;
Program:
#include<iostream.h>
#include<conio.h>
class
MCA
{
private:
int x,y;
public
:
void
getdata();
void
putdata();
};
void
MCA:: getdata()
{
cout<<”input
two number”;
cin>>x>>y;
}
void
MCA::putdata()
{
cout<<”x=”<<x;
cin>>x>>y;
}
void
main()
{
MCA
a1,a2;
a1.getdata();
a2=a1;
//object assignment
a1.putdata();
cout<<”after
data /n”;
a2.putdata();
getch();
}
Output:
Input
two number 20
30
x=20
y=30
after
data
x=20
y=30
No comments:
Post a Comment