单项选择题
现有:
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 Employee{ private String name; public Employee(String name){ this.name = name; } public void display(){ System.out.print(name); } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ super(name); this.department = department; } public void display(){ System.out.println( super.display()+”,”+department); } } 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()
A. smith,SALES
B. null,SALES
C. smith,null
D. null,null
