public class Main {
public static void main( String[] args)
{
Name tom = new Name();
Name jerry = new Name();
tom.setName("Tom");
jerry.setName("jerry");
swap(tom,jerry);
System.out.println("tom :" + tom.getName());
System.out.println("jerry :" + jerry.getName());
Name tom1 = new Name();
Name jerry1 = new Name();
tom1.setName("Tom1");
jerry1.setName("jerry1");
swap1(tom1,jerry1);
System.out.println("tom1 :" + tom1.getName());
System.out.println("jerry1 :" + jerry1.getName());
}
public static void swap(Name t,Name j)
{
Name temp = t ;
t = j;
j = temp;
}
public static void swap1(Name t,Name j)
{
String temp = t.getName();
t.setName(j.getName());
j.setName(temp);
}
}
class Name{
String name;
public String getName() {
ret
对变量执行交换方法,为什么值没有交换?public class Main { public static void main( String[] args) { Name tom = new Name(); Name jerry = new Name(); tom.setName("Tom"); jerry.setName("jerry"); swap...