马克社区吧 关注:484贴子:446
  • 0回复贴,共1

java当中也有pass-by-value值传递或pass-by-reference地址传递吗

只看楼主收藏回复

About Method’s arguments(参数)

In java, each of the method'sargument are passed(传递) to that method via(通过)pass-by-value(值传递) orpass-by-reference.(地址传递),这一点和c语言是一样的,


public class Test22{
/*以下是值传递的例子,结果改不了,*/
public static void modify(int k){
k = k*k;
}
/*以下是地址传递的例子,结果会改变,*/
public static void modify(int[] x){
for(int i=0; i<x.length; i++){
x[i] = x[i]*x[i];
}
}
public static void main(String[] args){
int i = 100;
int[] iArray = {1,2,3};
详情请见: http://www.mark-to-win.com/JavaBeginner/JavaBeginner1_web.html#pass-by-value


回复
本楼含有高级字体1楼2014-06-18 08:57

    扫二维码下载贴吧客户端

    下载贴吧APP
    看高清直播、视频!