java中方法参数的传递不管是引用类型还是原生类型,都是值传递
Demo:[code=java]Piont类
package com.cast.heima;
public class ;P oint {
int x = 0;
int y = 0;
}
运行类
package com.cast.heima;
public class ;P aramProblem {
public static void main(String[] args) {
Point point = new Point();
System.out.println("x:"+point.x+",y:"+point.y);//打印x:0,y:0
ParamProblem paramProblem = new ParamProblem();
//此处传递是实参
paramProblem.changePoint(point);
System.out.println("x:"+point.x+",y:"+point.y);//打印x:3,y:4
}
//此处传递是形参
public void changePoint(Point point) {
point.x = 3;
point.y = 4;
}
}[/code]
[ 本帖最后由 杨志罡 于 2011-07-29 00:01 编辑 ] |