Given the content of three files:
public class A {
public void a() {
}
int a;
}
public class B {
private int doStuff(){
private int x = 100;
return x++;
}
}
import java.io.*;
package p1;
class C {
public void main(String fileName) throws IOException {
}
}
Which statement is true?
A. Only the A.java file compiles successfully.
B. Only the B.java file compiles successfully.
C. Only the C.java file compiles successfully.
D. The A.Java and B.java files compile successfully.
E. The B.java and C.java files compile successfully.
F. The A.Java and C.java files compile successfully.
题解
「A.java」文件可以成功编译。
「B.java」文件会编译失败,因为 private、protected、public 等可见度修饰字只能使用在类别或是对象的字段和方法,并不能用在区域变量。
「C.java」文件会编译失败,因为「package」只能在所有程序叙述的最上方。
