Given the following code within a method: public class George
{
     private static int x = 2;     static void method1(int i)
     {
            x = i;
            ++i;
     }     public static void main(String[] args)
     {
            int i = 1;
            method1(i);
            System.out.println("x = " + x);
            System.out.println("i = " + i);
     }
}If the “main” method of this class is executed, the outputted values for “x” and “i”
respectively will be: (a) 1 and 1 
(b) 1 and 2
(c) 2 and 1
(d) 2 and 2能给个解释吗?万分感谢

解决方案 »

  1.   

    选择A吧第一个1就不用说,直接调用静态的method1方法,和前面的静态的X=2没任何关系,只起到定义的int类型的作用,java里面的变量都会以最后一个赋值为标准作为判断的
    而第二个用直接是主方法里面的i也就是1,默认的,打印也是主方法里的i,和在method1方法没任何关系,它也不返回任何对i的处理
    你可以试着在静态方法里随便给i赋值,结果无论如何都是1