Java 的传值原理,小例子_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Java 的传值原理,小例子

Java 的传值原理,小例子

 2011/11/24 10:44:25  lihui8848  http://lonelyisland.iteye.com  我要评论(0)
  • 摘要:publicclassTest{staticclassB{publicinti=0;publicStrings="0";}publicstaticvoidmain(String[]args){inti=0;change1(i);System.out.println(i);//0Stringa="0";change2(a);System.out.println(a);//0Bb1=newB();change3(b1);System.out.println(b1.i+""+b1.s)
  • 标签:例子 Java

public class Test {

??? static class B {
??????? public int i = 0;
??????? public String s = "0";
??? }

??? public static void main(String[] args) {
??????? int i = 0;
??????? change1(i);
??????? System.out.println(i);???????????????????????? //0

??????? String a = "0";
??????? change2(a);
??????? System.out.println(a);???????????????????????? //0

??????? B b1 = new B();
??????? change3(b1);
??????? System.out.println(b1.i + "?? " + b1.s);?????? //100? 100


??????? B b2 = new B();
??????? change4(b2);
??????? System.out.println(b2.i + "?? " + b2.s);?????? //0? 0
???????
??????? int[] c1 = new int[]{0};
??????? change5(c1);
??????? System.out.println(c1[0]);???????????????????? //100
???????
??????? int[] c2 = new int[]{0};
??????? change6(c2);
??????? System.out.println(c2[0]);???????????????????? //0
??? }

??? public static void change1(int i) {
??????? i = 100;
??? }

??? public static void change2(String a) {
??????? a = "100";
??? }

??? public static void change3(B b) {
??????? b.i = 100;
??????? b.s = "100";
??? }

??? public static void change4(B b) {
??????? b = new B();
??????? b.i = 100;
??????? b.s = "100";
??? }
???
??? public static void change5(int[] c) {???????
??????? c[0] = 100;
??? }
???
??? public static void change6(int[] c) {
??????? c = new int[]{100};???????
??? }
}

?

发表评论
用户名: 匿名