public class Test
{
public void changeApple(Apple a)
{
Apple a2 = new Apple();
a2.color = "red";
a = a2;
}
public void changeApple2(Apple a)
{
a.color = "red";
}
public static void main(String[] args)
{
Apple a = new Apple();
a.color="blue";
new Test().changeApple(a);
System.out.println(a.color);
new Test().changeApple2(a);
System.out.println(a.color);
}
}
class Apple
{
public String color;
}
//输出结果:blue
red
没有评论:
发表评论