本帖最后由 翟宝海 于 2013-5-28 10:08 编辑
- class Demo
- {
- public static void main(String[] args)
- {
- int x = 4;
- show(x);
- System.out.println(x);
- }
- public static void show(int x)
- {
- x = 2;
- }
- }
- //为什么运行结果是4?
- class Demo
- {
- int x = 3;
- public static void main(String[] args)
- {
- Demo d = new Demo();
- d.x = 10;
- show(d);//show(new Demo());
- System.out.println(d.x);
- }
- public static void show(Demo d)
- {
- d.x = 6;
- }
- }
- //运行结果是6;
- class Demo
- {
- public static void main(String[] args)
- {
- int[] arr = new int[2];
- show(arr);
- System.out.println(arr[0]);
- }
- public static void show(int[] arr)
- {
- arr[0]++;
- }
- }
- //运行结果是1;
复制代码 第二个和第三个可以理解,第一个还有些迷糊,试请诸位达者指点迷津! |