int a;
String b;
public SubTest(int a, String b){
this.a = a;
this.b = b;
}
}
public class MyTest {
private static void change(SubTest test){
test.a = 100;
test = new SubTest(10, "java");//方法中產生的是test的是副本
}
public static void main(String[] args) {
SubTest test = new SubTest(20, "hello");
change(test);
System.out.println(test.a);
}
}
結果:100