原题代码如下:
1 public voidtest1() {2 int a = 1, b = 2;3 System.out.println("before: a=" + a + ", b=" +b);4 swap1(a, b);5 System.out.println("after: a=" + a + ", b=" +b);6 }7
8 private void swap1(int i1, inti2) {9 int tmp =i1;10 i1 =i2;11 i2 =tmp;12 }13
14 public voidtest2() {15 Integer a = 1, b = 2;16 System.out.println("before: a=" + a + ", b=" +b);17 swap2(a, b);18 System.out.println("after: a=" + a + ", b=" +b);19 }20
21
22 public void test3() throwsNoSuchFieldException, IllegalAccessException {23 Integer a = 1, b = 2;24 System.out.println("before: a=" + a + ", b=" +b);25 swap3(a, b);26 System.out.println("after: a=" + a + ", b=" +b);27 }28
29
30 private voidswap2(Integer i1, Integer i2) {31 Integer tmp =i1;32 i1 =i2;33 i2 =tmp;34 }35
36 private void swap3(Integer i1, Integer i2) throwsNoSuchFieldException, IllegalAccessException {37 Field f = Integer.class.getDeclaredField("value");38 f.setAccessible(true);39 int tmp =i1.intValue();40 f.set(i1, i2.intValue());41 f.set(i2, tmp);42 }
题目
上述代码中,test1、test2、test3 方法运行后 a、b 前后的值分别是多少???
思考一下......黄金100秒......
......
......
......
答案放在本篇末尾,需要你稍稍滚动一下页面,并且希望是有思