单项选择题
现有:
1. class Book {
2. private final void read() { System.out.print("book "); }
3. }
4. class Page extends Book {
5. public static void main(String [] args) {
6. // insert code here
7. }
8. private final void read() { System.out.print("page "); }
9. }
和如下三个代码片段
( x, y, z ):
x. // just a comment
y. new Page().read();
z. new Book().read();
分别插入到第6行,有几个允许代码通过编译并可以运行且无异常?()
A. 0
B. 1
C. 2
D. 3
点击查看答案&解析
相关考题
-
单项选择题
现有: 1. interface Animal { 2. void eat(); 3. } 4. 5. // insert code here 6. 7. public class HouseCat implements Feline { 8. public void eat() { } 9. } 和以下三个接口声明: interface Feline extends Animal { } interface Feline extends Animal { void eat(); } interface Feline extends Animal { void eat() { } } 分别插入到第 5 行,有多少行可以编译?()
A. 0
B. 1
C. 2
D. 3 -
单项选择题
现有: class TestMain { static int x = 2; static { x = 4; } static public void main(String[] args) { int y = x + 1; System.out.println(y); } } 和命令行: java TestMain 结果为:()
A. 3
B. 5
C. 编译失败
D. 运行时异常被抛出 -
多项选择题
public class TestDemo{ private int x = 2; static int y = 3; public void method(){ final int i=100; int j = 10; class Cinner{ public void mymethod(){ //Here } } } } 在Here处可以访问的变量是哪些?()
A.x
B. y
C. i
D. j
