单选题10. interface A { void x(); }  11. class B implements A { public void x() { } public voidy() { } }  12. class C extends B { public void x() {} }  And:  20. java.util.List list = new java.util.ArrayList();  21. list.add(new B());  22. list.add(new C());

题目
单选题
10. interface A { void x(); }  11. class B implements A { public void x() { } public voidy() { } }  12. class C extends B { public void x() {} }  And:  20. java.util.List list = new java.util.ArrayList();  21. list.add(new B());  22. list.add(new C());  23. for (A a:list) {  24. a.x();  25. a.y();;  26. }  What is the result?()
A

 The code runs with no output.

B

 An exception is thrown at runtime.

C

 Compilation fails because of an error in line 20.

D

 Compilation fails because of an error in line 21.

E

 Compilation fails because of an error in line 23.

F

 Compilation fails because of an error in line 25.


相似考题
参考答案和解析
正确答案: F
解析: 暂无解析
更多“10. interface A { void x(); }  11. class B implements A { pu”相关问题
  • 第1题:

    interface Playable {

    void play();

    }

    interface Bounceable {

    void play();

    }

    interface Rollable extends Playable, Bounceable {

    Ball ball = new Ball("PingPang");

    }

    class Ball implements Rollable {

    private String name;

    public String getName() {

    return name;

    }

    public Ball(String name) {

    this.name = name;

    }

    public void play() {

    ball = new Ball("Football");

    System.out.println(ball.getName());

    }

    }

    这个错误不容易发现。


    正确答案:

     

    错。"interface Rollable extends Playable, Bounceable"没有问题。interface 可继承多个

    interfaces,所以这里没错。问题出在interface Rollable 里的"Ball ball = new Ball("PingPang");"。

    任何在interface 里声明的interface variable (接口变量,也可称成员变量),默认为public static

    final。也就是说"Ball ball = new Ball("PingPang");"实际上是"public static final Ball ball = new

    Ball("PingPang");"。在Ball 类的Play()方法中,"ball = new Ball("Football");"改变了ball 的

    reference,而这里的ball 来自Rollable interface,Rollable interface 里的ball 是public static final

    的,final 的object 是不能被改变reference 的。因此编译器将在"ball = new Ball("Football");"

    这里显示有错。

  • 第2题:

    1. public class GoTest {  2. public static void main(String[] args) {  3. Sente a = new Sente(); a.go();  4. Goban b = new Goban(); b.go();  5. Stone c = new Stone(); c.go();  6. }  7. } 8.  9. class Sente implements Go {  10. public void go() { System.out.println(”go in Sente.”); }  11. }  12.  13. class Goban extends Sente {  14. public void go() { System.out.println(”go in Goban”); }  15. }  16.  17. class Stone extends Goban implements Go { }  18.  19. interface Go { public void go(); }  What is the result?() 

    • A、 go in Goban     go in Sente go in Sente
    • B、 go in Sente      go in Sente go in Goban
    • C、 go in Sente     go in Goban go in Goban
    • D、 go in Goban    go in Goban go in Sente
    • E、 Compilation fails because of an error in line 17.

    正确答案:C

  • 第3题:

    interface Data { public void load(); }  abstract class Info { public abstract void load(); }  Which class correctly uses the Data interface and Info class?() 

    • A、 public class Employee extends Info implements Data { public void load() { /*do something*/ } }
    • B、 public class Employee implements Info extends Data { public void load() { /*do something*/ } }
    • C、 public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }
    • D、 public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }
    • E、 public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }
    • F、 public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }

    正确答案:A

  • 第4题:

    Given the following interface definition, which definitions are valid?()   interface I {   void setValue(int val);   int getValue();   }    DEFINITION a:   (a) class a extends I {  int value;   void setValue(int val) { value = val;  }   int getValue() {  return value;  }   }   DEFINITION b:   (b) interface b extends I {   void increment();   }   DEFINITION c:   (c) abstract class c implements I {   int getValue() {  return 0;  }  abstract void increment();   }   DEFINITION d:   (d) interface d implements I {  void increment();  }   DEFINITION e:   (e) class e implements I {  int value;   public void setValue(int val) { value = val; }  }  

    • A、Definition a.
    • B、Definition b.
    • C、Definition c.
    • D、Definition d.
    • E、Definition e.

    正确答案:B,C

  • 第5题:

    10. interface Foo {}  11. class Alpha implements Foo {}  12. class Beta extends Alpha {}  13. class Delta extends Beta {  14. public static void main( String[] args) {  15. Beta x = new Beta();  16. // insert code here  17. }  18. }  Which code, inserted at line 16, will cause a java.lang.ClassCastException?() 

    • A、 Alpha a = x;
    • B、 Foo f= (Delta)x;
    • C、 Foo f= (Alpha)x;
    • D、 Beta b = (Beta)(Alpha)x;

    正确答案:B

  • 第6题:

    多选题
    Given the following interface definition, which definitions are valid?()   interface I {   void setValue(int val);   int getValue();   }    DEFINITION a:   (a) class a extends I {  int value;   void setValue(int val) { value = val;  }   int getValue() {  return value;  }   }   DEFINITION b:   (b) interface b extends I {   void increment();   }   DEFINITION c:   (c) abstract class c implements I {   int getValue() {  return 0;  }  abstract void increment();   }   DEFINITION d:   (d) interface d implements I {  void increment();  }   DEFINITION e:   (e) class e implements I {  int value;   public void setValue(int val) { value = val; }  }
    A

    Definition a.

    B

    Definition b.

    C

    Definition c.

    D

    Definition d.

    E

    Definition e.


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

  • 第7题:

    单选题
    下列代码正确的是哪项?()
    A

     public class Session implements Runnable, Clonable{   public void run ();public Object clone () ; }

    B

     public class Session extends Runnable, Cloneable {  public void run() {/*dosomething*/}       public Object clone() {/*make a copy*/} }

    C

     public abstract class Session implements Runnable, Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}        }

    D

     public class Session implements Runnable, implements Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}       }


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

  • 第8题:

    单选题
    interface Data { public void load(); }  abstract class Info { public abstract void load(); }  Which class correctly uses the Data interface and Info class?()
    A

     public class Employee extends Info implements Data { public void load() { /*do something*/ } }

    B

     public class Employee implements Info extends Data { public void load() { /*do something*/ } }

    C

     public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }

    D

     public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }

    E

     public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }

    F

     public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }


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

  • 第9题:

    多选题
    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()
    A

    public class Circle implements Shape { private int radius; }

    B

    public abstract class Circle extends Shape { private int radius; }

    C

    public class Circle extends Shape { private int radius; public void draw(); }

    D

    public abstract class Circle implements Shape { private int radius; public void draw(); }

    E

    public class Circle extends Shape { private int radius;public void draw() {/* code here */} }

    F

    public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }


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

  • 第10题:

    单选题
    10. public class Foo implements java.io.Serializable {  11. private int x;  12. public int getX() { return x; }  12.publicFoo(int x){this.x=x; }  13. private void writeObject( ObjectOutputStream s)  14. throws IOException {  15. // insert code here  16. }  17. }  Which code fragment, inserted at line 15, will allow Foo objects to be correctly serialized and deserialized?()
    A

     s.writeInt(x);

    B

     s.serialize(x);

    C

     s.writeObject(x);

    D

     s.defaultWriteObject();


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

  • 第11题:

    单选题
    1. interface A { public void aMethod(); }  2. interface B { public void bMethod(); }  3. interface C extends A,B { public void cMethod(); }  4. class D implements B {  5. public void bMethod() { }  6. }  7. class E extends D implements C {  8. public void aMethod() { }  9. public void bMethod() { }  10. public void cMethod() { }  11. }  What is the result?()
    A

     Compilation fails because of an error in line 3.

    B

     Compilation fails because of an error in line 7.

    C

     Compilation fails because of an error in line 9.

    D

     If you define D e = new E(), then e.bMethod() invokes the version of bMethod()defined in Line 5.

    E

     If you define D e = (D)(new E()),then e.bMethod() invokes the version of bMethod() defined in Line 5.

    F

     If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9.


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

  • 第12题:

    多选题
    10. interface Jumper { public void jump(); }  ......  20. class Animal {}  ......  30. class Dog extends Animal { 31. Tail tail; 32. }  ......  40. class Beagle extends Dog implements Jumper {  41. public void jump() { }  42. }  .......  50. class Cat implements Jumper {  51. public void jump() { }  52. }  Which three are true?()
    A

    Cat is-a Animal

    B

    Cat is-a Jumper

    C

    Dog is-a Animal

    D

    Dog is-a Jumper

    E

    Cat has-a Animal

    F

    Beagle has-a Tail

    G

    Beagle has-a Jumper


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

  • 第13题:

    下列关于Test类的定义中,正确的是( )。

    A.class Test implements Runnable{ public void run{} Dublic void someMethod[]{} }

    B.class Test implements Runnable( puIblic void run; }

    C.class Test implements Runnable( Dublic void someMethod[]; }

    D.class Test implements Runnable( public void someMethod{} }


    正确答案:A
    A。【解析】java中实现多线程的方法之一就是实现Runnable接口中的run方法,把实现Runnable接口的子类对象传递给Thread类的构造函数。

  • 第14题:

    Which three demonstrate an “is a” relationship?() 

    • A、 public class X {  }     public class Y extends X { }
    • B、 public interface Shape { }     public interface Rectangle extends Shape{ }
    • C、 public interface Color { }     public class Shape { private Color color; }
    • D、 public interface Species { }     public class Animal { private Species species; }
    • E、 public class Person { }    public class Employee {      public Employee(Person person) { }
    • F、 interface Component { }     class Container implements Component {   private Component[] children; }

    正确答案:A,B,F

  • 第15题:

    下列代码正确的是哪项?() 

    • A、 public class Session implements Runnable, Clonable{   public void run ();public Object clone () ; }
    • B、 public class Session extends Runnable, Cloneable {  public void run() {/*dosomething*/}       public Object clone() {/*make a copy*/} }
    • C、 public abstract class Session implements Runnable, Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}        }
    • D、 public class Session implements Runnable, implements Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}       }

    正确答案:C

  • 第16题:

    现有:  interface Data {public void load();}  abstract class Info {public abstract void load();}      下列类定义中正确使用Data和Info的是哪项?() 

    • A、 public class Employee implements Info extends Data { public void load(){/*dosomething*/}     }
    • B、public class Employee extends Inf.implements Data{ public void load() {/*do something*/}     }
    • C、public class Empl.yee implements Inf extends Data{ public void Data.1oad(){* do something*/}     public void load(){/*do something*/}     }
    • D、public class Employee extends Inf implements Data  {  public void Data.1oad()  {/*do something*/)     public void info.1oad(){/*do something*/}    }

    正确答案:B

  • 第17题:

    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()

    • A、 public class Circle implements Shape { private int radius; }
    • B、 public abstract class Circle extends Shape { private int radius; }
    • C、 public class Circle extends Shape { private int radius; public void draw(); }
    • D、 public abstract class Circle implements Shape { private int radius; public void draw(); }
    • E、 public class Circle extends Shape { private int radius;public void draw() {/* code here */} }
    • F、 public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }

    正确答案:B,E

  • 第18题:

    多选题
    Given: 10. interface Jumper { public void jump(); } ...   20. class Animal {} ...   30. class Dog extends Animal {   31. Tail tail;   32. }   ...   40. class Beagle extends Dog implements Jumper{   41. public void jump() {}  42. }   ...   50. class Cat implements Jumper{   51. public void jump() {}   52. }. Which three are true?()
    A

    Cat is-a Jumper

    B

    Cat is-a Animal

    C

    Dog is-a Jumper

    D

    Dog is-a Animal

    E

    Beagle has-a Jumper

    F

    Cat has-a Animal

    G

    Beagle has-a Tail


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

  • 第19题:

    单选题
    现有:  interface Data {public void load();}  abstract class Info {public abstract void load();}      下列类定义中正确使用Data和Info的是哪项?()
    A

     public class Employee implements Info extends Data { public void load(){/*dosomething*/}     }

    B

    public class Employee extends Inf.implements Data{ public void load() {/*do something*/}     }

    C

    public class Empl.yee implements Inf extends Data{ public void Data.1oad(){* do something*/}     public void load(){/*do something*/}     }

    D

    public class Employee extends Inf implements Data  {  public void Data.1oad()  {/*do something*/)     public void info.1oad(){/*do something*/}    }


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

  • 第20题:

    多选题
    Which three demonstrate an “is a” relationship?()
    A

    public class X {  }     public class Y extends X { }

    B

    public interface Shape { }     public interface Rectangle extends Shape{ }

    C

    public interface Color { }     public class Shape { private Color color; }

    D

    public interface Species { }     public class Animal { private Species species; }

    E

    public class Person { }    public class Employee {      public Employee(Person person) { }

    F

    interface Component { }     class Container implements Component {   private Component[] children; }


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

  • 第21题:

    单选题
    10. interface A { void x(); }  11. class B implements A { public void x() { } public voidy() { } }  12. class C extends B { public void x() {} }  And:  20. java.util.List list = new java.util.ArrayList();  21. list.add(new B());  22. list.add(new C());  23. for (A a:list) {  24. a.x();  25. a.y();;  26. }  What is the result?()
    A

     The code runs with no output.

    B

     An exception is thrown at runtime.

    C

     Compilation fails because of an error in line 20.

    D

     Compilation fails because of an error in line 21.

    E

     Compilation fails because of an error in line 23.

    F

     Compilation fails because of an error in line 25.


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

  • 第22题:

    单选题
    10. interface Foo {}  11. class Alpha implements Foo {}  12. class Beta extends Alpha {}  13. class Delta extends Beta {  14. public static void main( String[] args) {  15. Beta x = new Beta();  16. // insert code here  17. }  18. }  Which code, inserted at line 16, will cause a java.lang.ClassCastException?()
    A

     Alpha a = x;

    B

     Foo f= (Delta)x;

    C

     Foo f= (Alpha)x;

    D

     Beta b = (Beta)(Alpha)x;


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

  • 第23题:

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

  • 第24题:

    单选题
    现有:  interface Animal {       void eat () ;       }       //insert code here       public class HouseCat extends Feline {       public void eat() { }       }  和五个申明  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();} 结果为:()
    A

    1

    B

    2

    C

    3

    D

    4


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