package chunf.test;
public class Test2 {
//??? public static void doTest(int i, int j) {?? 
//??????? int a = i;?? 
//??????? i = j;?? 
//??????? j = a;?? 
//??? }?? 
//? 
//??? public static void main(String[] args) {?? 
//??????? int a = 3;?? 
//??????? int b = 4;?? 
//??????? doTest(a, b);?? 
//? 
//??????? System.out.println("a=" + a);?? 
//??????? System.out.println("b=" + b);?? 
//??? }
??? //以上输出的是 3 4 虽然走了doTest方法 但是,传递的只是对a b 的引用,并未改变a b 的值。
//-----------------------------------------------------------------------------------? 
//??? public static void doTest(int[] counts) {?? 
//??????? counts[0] = 6;?? 
//??????? System.out.println(counts[0]);?? 
//??? }?? 
//? 
//??? public static void main(String[] args) {?? 
//??????? int[] count = { 1, 2, 3};?? 
//??????? doTest(count);?? 
//??? }??? 
//以上输出为6,因为数组传递至方法内,方法将数组改变并在改变后打印改变后的值。
//----------------------------------------------------------------------------------
//??? public static void doTest(Test1 a) {?? 
//??????? a = new Test1();?? 
//??????? a.a++;?? 
//??? }?? 
//?????? 
//??? public static void main(String args[]) {?? 
//??? ??? Test1 a = new Test1();?? 
//??????? doTest(a);?? 
//??????? System.out.println(a.a);?? 
//??? } 
/*
?* Test1{
?*? int a = 2;
?* }
?* */
//以上输出依然为TEST1类中的初始a值,原因是a并非静态的变量,每当new一个新的类,指针指向的地址是变化的。并非被方法处理的TEST1类
//------------------------------------------------------------------------------------
//??? public static void doTest(Test1 a) {?? 
//??????? a = new Test1();?? 
//??????? a.a++;?? 
//??? }?? 
//?????? 
//??? public static void main(String args[]) {?? 
//??? ??? Test1 a = new Test1();?? 
//??????? doTest(a);?? 
//??????? System.out.println(a.a);?? 
//??? } 
/*
* Test1{
*? static int a = 2;
* }
* */
//以上输出为3,因为TEST1类中的变量a是静态的,因此无论new了多少个TEST1类,变量a的地址是不变的。所以操作的都是同一个a
//例如下面例子
//public static void doTest(Test1 a){
//??? a = new Test1();
//??? a.a++;
//}
//
//public static void main(String[] args) {
//??? Test1 tst1 = new Test1();
//??? doTest(tst1);
//??? Test1 tst2 = new Test1();
//??? doTest(tst2);
//??? System.out.println(tst1.a);
//??? System.out.println(tst2.a);
//}
//这两行输出都是4,因为无论是tst1还是tst2,变量a的地址是不变的,操作的都是同一个a
//----------------------------------------------------------------------------------
//??? String str = new String("haha");?? 
//??? ? 
//??? char[] ch = { 'a', 'b', 'c' };?? 
? 
//??? public static void main(String args[]) {?? 
//??? ??? Test2 tst = new Test2();?? 
//??????? ex.change(tst.str, tst.ch);?? 
//??????? System.out.print(tst.str + " and ");?? 
//??????? System.out.println(tst.ch);?? 
//??? }?? 
//? 
//??? public void change(String str, char ch[]) {?? 
//??????? str = "lalala";?? 
//??????? ch[0] = 'd';?? 
//??? }? 
//以上输出haha and dbc由于String是final的,那么tst.str是不被改变的。而数组并非如此,因此数组被改变
}??