class Args4
{
int a,b;
Args4(int x, int y)
{
a = x;
b = y;
}
static void swap(Args4 ob1,Args4 ob2)
{
int x,y;
x = ob1.a;
y = ob1.b;
ob1.a = ob2.a;
ob1.b = ob2.b;
ob2.a = x;
ob2.b = y;
}
public static void main(String[] args)
{
Args4 obj1 = new Args4(5,7);
Args4 obj2 = new Args4(4,6);
System.out.print("obj1.a = "+obj1.a+" obj1.b = "+obj1.b);
System.out.println(" obj2.a = "+obj2.a+" obj2.b = "+obj2.b);
swap(obj1,obj2);
System.out.print("obj1.a = "+obj1.a+" obj1.b = "+obj1.b);
System.out.println(" obj2.a = "+obj2.a+" obj2.b = "+obj2.b);
}
}
OUTPUT
Comments
Post a Comment