Topic: 关于JAVA中方法传值与传变量的问题

  Print this page

1.关于JAVA中方法传值与传变量的问题 Copy to clipboard
Posted by: qileroro
Posted on: 2004-10-04 17:53

小弟刚接触JAVA不知道JAVA中的方法的参数默认是传值的还是传变量,
请告知一下,JAVA中是否有相关的设置???

2.Re:关于JAVA中方法传值与传变量的问题 [Re: qileroro] Copy to clipboard
Posted by: abu
Posted on: 2004-10-04 19:57

没有默认不默认的,
当传基本的数据类型时,就是传值,
当传递的类时,就是传址了,!!

3.Re:关于JAVA中方法传值与传变量的问题 [Re: qileroro] Copy to clipboard
Posted by: hvbird
Posted on: 2004-10-04 23:55

你可以自己做几个例子实践实践,这样印象更深!

4.Re:关于JAVA中方法传值与传变量的问题 [Re: qileroro] Copy to clipboard
Posted by: nothing
Posted on: 2004-10-05 04:05


//: c03:PassObject.java
// Passing objects to methods may not be what
// you're used to.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.

public class PassObject {

static void f(Letter y) {
y.c = 'z';
}

public static void main(String[] args) {
Letter x = new Letter();
x.c = 'a';
System.out.println("1: x.c: " + x.c);
f(x);
System.out.println("2: x.c: " + x.c);
}
}

class Letter {
char c;
}


--------------------------------------
1: x.c: a
2: x.c: z


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923