niusouti.com

现有:   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("pa

题目

现有:   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. 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("pag”相关问题
  • 第1题:

    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

  • 第2题:

    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

  • 第3题:

    1. import java.util.*;  2. class ForInTest {  3. static List list = new ArrayList();  4.  5. static List getList() { return list; }  6.  7. public static void main(String [] args) {  8. list.add("a"); list.add("b"); list.add("c");  9. // insert code here  10. System.out.print(o);  11. }  12. } 第 9 行插入哪一项将输出 abc?() 

    • A、for(char o: list)
    • B、for(Object o: getList())
    • C、for(Object o: getList();)
    • D、for(Object o: o.getList())

    正确答案:B

  • 第4题:

    1. class Passer2 {   2. //insert code here   3. static int bigState = 42;   4. public static void main(String [] args) {   5. bigState = p2.go(bigState);   6. System.out.print(bigState);   7. }   8. int go(int x) {   9. return ++x;   10. }   11. }  和4段代码片段:  static Passer2 p2 = new Passer2();  final static Passer2 p2 = new Passer2();  private static Passer2 p2 = new Passer2();  final private static Passer2 p2 = new Passer2();  有多少行分别插入到第2行,可以编译?()  

    • A、0
    • B、1
    • C、3
    • D、4

    正确答案:D

  • 第5题:

    class Passer {  static final int x = 5;  public static void main(String [] args) { new Passer().go(x);  System.out.print(x);  }  void go(int x) {  System.out.print(++x);  }  }  结果是什么?() 

    • A、55
    • B、56
    • C、65
    • D、66

    正确答案:C

  • 第6题:

    Given classes defined in two different files:  1. package util;  2. public class BitUtils {  3. public static void process(byte[]) { /* more code here */ }  4. }  1. package app;  2. public class SomeApp {  3. public static void main(String[] args) {  4. byte[] bytes = new byte[256];  5. // insert code here  6. }  7. }  What is required at line 5 in class SomeApp to use the process method of BitUtils?() 

    • A、 process(bytes);
    • B、 BitUtils.process(bytes);
    • C、 util.BitUtils.process(bytes);
    • D、 SomeApp cannot use methods in BitUtils.
    • E、 import util.BitUtils.*; process(bytes);

    正确答案:C

  • 第7题:

    Given a class Repetition:  1. package utils;  2.  3. public class Repetition {  4. public static String twice(String s) { return s + s; }  5. }  and given another class Demo:  1. // insert code here 2.  3. public class Demo {  4. public static void main(String[] args) {  5. System.out.println(twice(”pizza”));  6. }  7. }  Which code should be inserted at line 1 of Demo.java to compile and run Demo to print“pizzapizza”?() 

    • A、 import utils.*;
    • B、 static import utils.*;
    • C、 import utils.Repetition.*;
    • D、 static import utils.Repetition. *;
    • E、 import utils.Repetition.twice();
    • F、 import static utils.Repetition.twice;
    • G、 static import utils.Repetition.twice;

    正确答案:F

  • 第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题:

    单选题
    Given classes defined in two different files:  1. package util;  2. public class BitUtils {  3. private static void process(byte[] b) { }  4. }  1. package app;  2. public class SomeApp {  3. public static void main(String[] args) {  4. byte[] bytes = new byte[256];  5. // insert code here  6. }  7. }  What is required at line 5 in class SomeApp to use the process method of BitUtils?()
    A

     process(bytes);

    B

     BitUtils.process(bytes);

    C

     app.BitUtils.process(bytes);

    D

     util.BitUtils.process(bytes);

    E

     import util.BitUtils. *; process(bytes);

    F

     SomeApp cannot use the process method in BitUtils.


    正确答案: A
    解析: 暂无解析

  • 第10题:

    单选题
    class Passer {  static final int x = 5;  public static void main(String [] args) { new Passer().go(x);  System.out.print(x);  }  void go(int x) {  System.out.print(++x);  }  }  结果是什么?()
    A

    55

    B

    56

    C

    65

    D

    66


    正确答案: D
    解析: 暂无解析

  • 第11题:

    单选题
    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
    解析: 暂无解析

  • 第12题:

    单选题
    public class Base {  public static final String FOO = “foo”;  public static void main(String[] args) {  Base b = new Base();  Sub s = new Sub();  System.out.print(Base.FOO);  System.out.print(Sub.FOO);  System.out.print(b.FOO);  System.out.print(s.FOO);  System.out.print(((Base)s).FOO);  } }  class Sub extends Base {public static final String FOO=bar;}  What is the result?()
    A

     foofoofoofoofoo

    B

     foobarfoobarbar

    C

     foobarfoofoofoo

    D

     foobarfoobarfoo

    E

     barbarbarbarbar

    F

     foofoofoobarbar

    G

     foofoofoobarfoo


    正确答案: B
    解析: 暂无解析

  • 第13题:

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

  • 第14题:

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

  • 第15题:

    1. class Calc {  2. public static void main(String [] args) {  3. try {  4. int x = Integer.parseInt("42a");  5. //insert code here  6. System.out.print("oops ");  7. }  8. }  9. }  下面哪两行分别插入到第五行,会导致输出“oops”?()

    • A、} catch (ClassCastException c) {
    • B、} catch (IllegalStateException c) {
    • C、} catch (NumberFormatException n) {
    • D、} catch (IllegalArgumentException e) {

    正确答案:C,D

  • 第16题:

    1. class MyThread implements Runnable {  2. public void run() {  3. System.out.print("go ");  4. }  5.  6. public static void main(String [] args) {  7. // insert code here  8. t.start(); 9. }  10. }  和如下四句:  Thread t = new MyThread(); MyThread t = new MyThread();  Thread t = new Thread(new Thread());  Thread t = new Thread(new MyThread());  分别插入到第5行,有几个可以通过编译?() 

    • A、0
    • B、1
    • C、2
    • D、3

    正确答案:C

  • 第17题:

    Given classes defined in two different files:  1. package util;  2. public class BitUtils {  3. private static void process(byte[] b) { }  4. }  1. package app;  2. public class SomeApp {  3. public static void main(String[] args) {  4. byte[] bytes = new byte[256];  5. // insert code here  6. }  7. }  What is required at line 5 in class SomeApp to use the process method of BitUtils?() 

    • A、 process(bytes);
    • B、 BitUtils.process(bytes);
    • C、 app.BitUtils.process(bytes);
    • D、 util.BitUtils.process(bytes);
    • E、 import util.BitUtils. *; process(bytes);
    • F、 SomeApp cannot use the process method in BitUtils.

    正确答案:F

  • 第18题:

    1. public class enclosingone (  2. public class insideone{}  3. )  4. public class inertest(  5. public static void main (string[]args)(  6. enclosingone eo= new enclosingone ();  7. //insert code here  8. )  9. )    Which statement at line 7 constructs an instance of the inner class?()  

    • A、 InsideOnew ei= eo.new InsideOn();
    • B、 Eo.InsideOne ei = eo.new InsideOne();
    • C、 InsideOne ei = EnclosingOne.new InsideOne();
    • D、 EnclosingOne.InsideOne ei = eo.new InsideOne();

    正确答案:D

  • 第19题:

    现有:  1. interface Animal {  2. void eat();  3. }  4.  5. // insert code here  6.  7. public class HouseCat extends Feline {  8. public void eat() { }  9. }   和五个声明:  abstract class Feline implements Animal { }  abstract class Feline implements Animal { void eat(); }  abstract class Feline implements Animal { public void eat(); }  abstract class Feline implements Animal { public void eat() { } }  abstract class Feline implements Animal { abstract public void eat(); }  分别插入到第5行,有几个可以通过编译?() 

    • A、0
    • B、1
    • C、2
    • D、3

    正确答案:D

  • 第20题:

    现有   1. class Calc {  2.  public static void main(String [] args) {   3.    try {  4.         int x = Integer.parselnt ("42a") ;   5.     //insert code here  6.         System.out.print ("oops");   7.    }   8.   }   9. }   下面哪两行分别插入到第五行,会导致输 "oops" ? () 

    • A、 } catch (IllegalArgumentException e) {
    • B、 } catch (IllegalStateException c) {
    • C、 } catch (NumbelFormatException n) {
    • D、 } catch (ClassCastException c) {

    正确答案:A,C

  • 第21题:

    多选题
    1. class Calc {  2. public static void main(String [] args) {  3. try {  4. int x = Integer.parseInt("42a");  5. //insert code here  6. System.out.print("oops ");  7. }  8. }  9. }  下面哪两行分别插入到第五行,会导致输出“oops”?()
    A

    } catch (ClassCastException c) {

    B

    } catch (IllegalStateException c) {

    C

    } catch (NumberFormatException n) {

    D

    } catch (IllegalArgumentException e) {


    正确答案: A,B
    解析: 暂无解析

  • 第22题:

    单选题
    1. public class enclosingone (  2. public class insideone{}  3. )  4. public class inertest(  5. public static void main (string[]args)(  6. enclosingone eo= new enclosingone ();  7. //insert code here  8. )  9. )    Which statement at line 7 constructs an instance of the inner class?()
    A

     InsideOnew ei= eo.new InsideOn();

    B

     Eo.InsideOne ei = eo.new InsideOne();

    C

     InsideOne ei = EnclosingOne.new InsideOne();

    D

     EnclosingOne.InsideOne ei = eo.new InsideOne();


    正确答案: C
    解析: 暂无解析

  • 第23题:

    多选题
    现有   1. class Calc {  2.  public static void main(String [] args) {   3.    try {  4.         int x = Integer.parselnt ("42a") ;   5.     //insert code here  6.         System.out.print ("oops");   7.    }   8.   }   9. }   下面哪两行分别插入到第五行,会导致输 "oops" ? ()
    A

    } catch (IllegalArgumentException e) {

    B

    } catch (IllegalStateException c) {

    C

    } catch (NumbelFormatException n) {

    D

    } catch (ClassCastException c) {


    正确答案: A,D
    解析: 暂无解析