public class swap
{ public void sswap(int x,int y){ int s; s=x; x=y; y=s; System.out.println("Within sswap: x="+x+" y="+y); } public static void main(String args[]){ int x=10,y=7; System.out.println("x="+x+" y="+y); swap s=new swap(); s.sswap(x,y); System.out.println("x="+x+" y="+y); } }输出结果:
x=10,y=7
within sswap:x=7,y=10
x=10,y=7
传进sswap()方法内的仅仅是值而已。