SCJP问题(1)
1iuri 2004-11-04 04:19:24 Q1. Given:
1. package test1;
2. public class Test1 {
3. static int x = 42;
4. }
1. package test2;
2. public class Test2 extends test1.Test1 {
3. public static void main(String[] args) {
4. System.out.printIn(“x = “ + x);
5. }
6. }
What is the result?
A. x = 0
B. x = 42
C. Compilation fails because of an error in line 2 of class Test2.
D. Compilation fails because of an error in line 3 of class Test1.
E. Compilation fails because of an error in line 4 of class Test2.
我想编译出错的原因是静态变量不能跨包访问
而运行这段代码,也会提示:
x is not public in test1.Test1;cannot be accessed form outside package
所以我觉得答案应该是E,但答案D ,不知为何?