//java swaping program to pass object through their references-------PROGRAM CODE---
class Swap{
int a,b;
Swap(int i , int j)
{
a=i;
b=j;
}
void swapping(Swap ob)
{
ob.a=ob.a+ob.b;
ob.b=ob.a-ob.b;
ob.a=ob.a-ob.b;
}
}
class CallSwap
{
public static void main(String ar[])
{
Swap s = new Swap(30,40);
System.out.println("Before Swaping");
System.out.println("Value of a is"+s.a);
System.out.println("Value of b is"+s.b);
s.swapping(s);
System.out.println("After Swaping");
System.out.println("Value of a is"+s.a);
System.out.println("Value of b is"+s.b);
}
}



Comments
Post a Comment