JAVA引用類型與基本類型

package third;

public class TransByValue {
	public static void main(String[] args) {
		int a = 0;
		modify(a);System.out.println(a); // result = 0
		int[] b = new int [1];
		modify(b);
		System.out.println(b[0]); //result = 1
		//System.out.println(b[1]); wrong
	}
	public static void modify(int a) {
		a++;
	}
	public static void modify(int[] b) {
		b[0]++;
		b = new int [5];
		b[0]++;
		b[0]++;
		b[1] = 2;
	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章