[10]基本型別和引用型別的引數傳遞(圖)
阿新 • • 發佈:2018-12-12
前言:主要為個人筆記
基本型別
程式碼:
class Demo{
public static void main(String[] args){
int x=4;
show(x);
System.out.println(x);
}
public static void /* int */ show(int x){
x=5;
//return;
}
}
圖:
最後結果還是4,無論有沒有返回值
引用型別
程式碼:
class Demo{ int x; void show(Demo d){ d.x=5; } } class DemoTest{ public static void main(String[] args){ Demo d=new Demo(); d.x=4; d.show(d); System.out.println(d.x); } }
圖:
最終結果為5