source file name: simple1.java 

class Swap

{

int a,b;

void set(int m,int n)

{

a=m;

b=n;

}

void show()    

{

System.out.println("a="+a+" b="+b);

}

void swap()

{

int t=a;

a=b;

b=t;

}

}

class simple1

{

public static void main(String as[])

{

Swap ob=new Swap();

ob.set(10,20);

System.out.println("Original values:");

ob.show();

ob.swap();

System.out.println("swapped values:");

ob.show();

}

}

output:


D:\JavaPrograms>javac simple1.java

D:\JavaPrograms>java simple1
Original values:
a=10 b=20
swapped values:
a=20 b=10

D:\JavaPrograms>javac simple1.java

D:\JavaPrograms>java simple1
Original values:
a=70 b=-25
swapped values:
a=-25 b=70