文章出處

引用傳遞

class Ref1{

int temp=10;

}

public class RefDemo01{

public static void main(String args[]){

Ref1 r1=new Ref1();//實例化對象

r1.temp=20;

System.out.println(r1.temp);

tell(r1);

System.out.println(r1.temp);

 

}

public static void tell(Ref1 r2){

r2.temp=30;

}

}

打印出

20

30

 

public class RefDemo02{

public static void main(String[] args){

String str1="Hello";

System.out.println(str1);

tell(str1);

System.out.println(str1)

}

public static void tell(String str2)

{

str2="jike"

}

}

打印只顯示Hello

hello

String是不可改變的

所以與上面情況不同

 

 


this關鍵字
static關鍵字


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()