
程序主代码如下: class A{ static int i=10; public static void main(String[] args){ int i=20; System.out.println("i的值为:"+i); System.out.println("i的值为:"+A.i); } } A. 10 20 B. 20 10 C. 10 10 D. 20 20
In Java, when a local variable has the same name as a static class variable, the local variable takes precedence within its scope. The code defines two i variables: a static class variable A.i = 10 and a local variable i = 20 in the main method.
The first print statement System.out.println("i的值为:"+i) uses the local variable i (since it’s in the same scope as the main method), outputting 20. The second statement System.out.println("i的值为:"+A.i) explicitly references the static class variable via A.i, outputting 10.
Answer: B