现有:   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() { Syst

题目

现有:   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
参考答案和解析
正确答案:C
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

1. public class Target {  2. private int i = 0;  3. public int addOne() {  4. return ++i;  5. }  6. }  And:  1. public class Client {  2. public static void main(String[] args) {  3. System.out.println(new Target().addOne());  4. }  5. }  Which change can you make to Target without affecting Client?() 

  • A、 Line 4 of class Target can be changed to return i++;
  • B、 Line 2 of class Target can be changed to private int i = 1;
  • C、 Line 3 of class Target can be changed to private int addOne() {
  • D、 Line 2 of class Target can be changed to private Integer i = 0;

正确答案:D

第2题:

Which declarations will allow a class to be started as a standalone program?()  

  • A、public void main(String args[])
  • B、public void static main(String args[])
  • C、public static main(String[] argv)
  • D、final public static void main(String [] array)
  • E、public static void main(String args[])

正确答案:D,E

第3题:

1. public class SimpleCalc {  2. public int value;  3. public void calculate() { value += 7; }  4. } And:  1. public class MultiCalc extends SimpleCalc {  2. public void calculate() { value -= 3; }  3. public void calculate(int multiplier) {  4. calculate();  5. super.calculate();  6. value *=multiplier;  7. }  8. public static void main(String[] args) {  9. MultiCalc calculator = new MultiCalc();  10. calculator.calculate(2);  11. System.out.println(”Value is: “+ calculator.value);  12. }  13. }  What is the result?() 

  • A、 Value is: 8
  • B、 Compilation fails.
  • C、 Value is: 12
  • D、 Value is: -12
  • E、 The code runs with no output.
  • F、 An exception is thrown at runtime.

正确答案:A

第4题:

现有2 个文件:  1. package x;  2. public class X {  3. public static void doX() { System.out.print("doX "); }  4. }  和:  1. class Find {  2. public static void main(String [] args) {  3. //insert code here  4. }  5. }  哪两行分别插入到类Find 的第3 行将编译并产生输出“doX”? ()

  • A、doX();
  • B、X.doX();
  • C、x.X.doX();
  • D、x.X myX = new x.X(); myX.doX();

正确答案:C,D

第5题:

现有:   1.  class HorseRadish {   2.    // insert code here   3.    protected HorseRadish(int x) {    4.      System.out.println("bok choy");  5.    }  6.  }   7.  class Wasabi extends HorseRadish {   8.    public static void main(String [] args) {   9.      Wasabi w = new Wasabi();  10.   }    11. }   分别插入到第 2 行,哪两项允许代码编译并产生"bok choy" 输出结果?() 

  • A、 // just a comment
  • B、 protected HorseRadish() { }
  • C、 protected HorseRadish() { this(42);}
  • D、 protected  HorseRadish() { new HorseRadish (42);}

正确答案:C,D

第6题:

1. public interface A {  2. public void doSomething(String thing);  3. }  1. public class AImpl implements A {  2. public void doSomething(String msg) { }  3. }  1. public class B {  2. public A doit() {  3. // more code here  4. }  5.  6. public String execute() { 7. // more code here  8. }  9. }  1. public class C extends B {  2. public AImpl doit() {  3. // more code here  4. }  5.  6. public Object execute() {  7. // more code here  8. }  9. }  Which statement is true about the classes and interfaces in the exhibit?() 

  • A、 Compilation will succeed for all classes and interfaces.
  • B、 Compilation of class C will fail because of an error in line 2.
  • C、 Compilation of class C will fail because of an error in line 6.
  • D、 Compilation of class AImpl will fail because of an error in line 2.

正确答案:C

第7题:

1. public class A {  2. void A() {  3. System.out.println(“Class A”);  4. }  5. public static void main(String[] args) {  6. new A();  7. }  8. }  What is the result?()  

  • A、 Class A
  • B、 Compilation fails.
  • C、 An exception is thrown at line 2.
  • D、 An exception is thrown at line 6.
  • E、 The code executes with no output.

正确答案:E

第8题:

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

正确答案:C

第9题:

1. class Pizza {  2. java.util.ArrayList toppings;  3. public final void addTopping(String topping) {  4. toppings.add(topping); 5. }  6. }  7. public class PepperoniPizza extends Pizza {  8. public void addTopping(String topping) {  9. System.out.println(”Cannot add Toppings”);  10. }  11. public static void main(String[] args) {  12. Pizza pizza = new PepperoniPizza();  13. pizza.addTopping(”Mushrooms”);  14. }  15. }  What is the result?() 

  • A、 Compilation fails.
  • B、 Cannot add Toppings
  • C、 The code runs with no output.
  • D、 A NullPointerException is thrown in Line 4.

正确答案:A

第10题:

现有:   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

正确答案:C

更多相关问题