pre name = "code" class = "java" span style = "font-size:24px;" package test ; public class PassValue { //引用数据类型传递的是地址值 int i = 10 ; public static void main ( String [] args ) { PassValue p2 = new PassValue (); Sys
public class PassValue {
//引用数据类型传递的是地址值
int i = 10;
public static void main(String[] args) {
PassValue p2 = new PassValue();
System.out.println("方法调用前i的值为" + p2.i);//10
ChangeValue(p2);//将p2的值赋给方法中的p,就是将p2的地址值给p
System.out.println("方法调用后i的值为" + p2.i);//100
}
private static void ChangeValue(PassValue p) {//PassValue p=p2;
System.out.println("接收到的值为"+p.i);//10
p.i = 100;
System.out.println("方法中i的值为" + p.i);//100
}
}
</span>