請問為什么在第一個程序中可以出現輸出不同值,但是第二個程序不行?class Ref1{
int temp=10;
}
public class ClassDemo05 {
public static void main(String[] args) {
Ref1 ref1=new Ref1();
ref1.temp=20;
System.out.println(ref1.temp);
tell(ref1);
System.out.println(ref1.temp);
}
public static void tell(Ref1 ref2) {
ref2.temp=30;
}
}
public class ClassDemo07 {
public static void main(String[] args) {
int a=10;
System.out.println(a);
tell(a);
System.out.println(a);
}
public static void tell(int b) {
b =30;
}
}
關于java引用傳遞的問題
臨摹微笑
2018-07-01 10:07:50