基本数据类型
(show()方法出栈 栈里面只有成员变量)
1 2 3 4 5 6 7 8 9 10 11 12
| package 引用传递;
public class Demo { public static void main(String[] args) { int x = 3; show(x); System.out.println("x=" + x); } public static void show(int x) { x = 4; } }
|


1 2 3 4 5 6 7 8 9 10 11 12
| package 引用传递;
public class Demo { public static void main(String[] args) { int x = 3; show(x); } public static void show(int x) { x = 4; System.out.println("x=" + x); } }
|


引用数据类型参数传递

1 2 3 4 5 6 7 8 9 10 11 12 13 14
| package 引用传递;
public class Demo2 { int x = 3; public static void main(String[] args) { Demo2 demo2 = new Demo2(); demo2.x=9; show(demo2); System.out.println(demo2.x); } public static void show(Demo2 d) { d.x = 4; } }
|


总结

引用数据类型传递详解
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| package 引用传递;
class Demo1 { private int data = 10;
public Demo1() { }
public Demo1(int data) { this.data = data; }
public int getData() { return this.data; }
public void setData(int data) { this.data = data; } }
public class TestDemo { public static void main(String[] args) { Demo1 demo1 = new Demo1(); fun(demo1); System.out.println(demo1.getData()); }
public static void fun(Demo1 temp) { temp.setData(30); }
}
|


https://blog.csdn.net/lym152898/article/details/54411956







Author:
John Doe
Permalink:
http://yoursite.com/2018/12/04/java基础/引用传递/
License:
Copyright (c) 2019 CC-BY-NC-4.0 LICENSE
Slogan:
Do you believe in DESTINY?