形参也是局部变量, method(new Test()) 带入匿名对象到method方法后执行了t.num = 6;就被释放了,所以System.out.println(t.num);打印的是 Test t = new Test();这个对象中的num
class Test {
int num = 3;
public static void main(String[] args) {
Test t = new Test();
t.num = 5;
method(new Test());
System.out.println(t.num);
}
public static void method(Test t){
t.num = 6;
}
}