单选题11. abstract class Vehicle { public int speed() { return 0; } }  12. class Car extends Vehicle { public int speed() { return 60; } }  13. class RaceCar extends Car { public int speed() { return 150; }}  ......  21. RaceCar racer = new RaceCar();  22. C

题目
单选题
11. abstract class Vehicle { public int speed() { return 0; } }  12. class Car extends Vehicle { public int speed() { return 60; } }  13. class RaceCar extends Car { public int speed() { return 150; }}  ......  21. RaceCar racer = new RaceCar();  22. Car car = new RaceCar();  23. Vehicle vehicle = new RaceCar();  24. System.out.println(racer.speed() + “, „ + car.speed()  25. + “, “+ vehicle.speed());  What is the result?()
A

 0, 0,0

B

 150, 60, 0

C

 Compilation fails.

D

 150, 150, 150

E

 An exception is thrown at runtime.


相似考题
参考答案和解析
正确答案: B
解析: 暂无解析
更多“单选题11. abstract class Vehicle { public int speed() { return 0; } }  12. class Car extends Vehicle { public int speed() { return 60; } }  13. class RaceCar extends Car { public int speed() { return 150; }}  ......  21. RaceCar racer = new RaceCar();  22. C”相关问题
  • 第1题:

    Given:Which code, inserted at line 15, allows the class Sprite to compile?()

    A.Foo { public int bar() { return 1; }

    B.new Foo { public int bar() { return 1; }

    C.new Foo() { public int bar() { return 1; }

    D.new class Foo { public int bar() { return 1; }


    参考答案:C

  • 第2题:

    阅读以下说明和Java代码,填充程序中的空缺,将解答填入答题纸的对应栏内。
    [说明]
    某应急交通控制系统(TraficControlSystem)在红灯时控制各类车辆(Vehicle)的通行,其类图如下图所示,在紧急状态下应急车辆在红灯时可通行,其余车辆按正常规则通行。

    下面的Java代码实现以上设计,请完善其中的空缺。

    [Java代码]abstract class Vehicle{public Vehicle(){ }abstract void run();};interface Emergency{ ______; ______;};class Car extends Vehicle{public Car(){ }void run(){ /*代码略*/ }};Class Truck extends Vehicle{public Truck(){ }void run() { /*代码略*/ }};class PoliceCar ______ {boolean isEmergency= false;public PoliceCar(){ }public PoliceCar(boolean b) {this.isEmergency=b; }public boolean isEmergent(){ return ______ }public void runRedLight(){ /*代码略*/ }};/*类Ambulance、FireEngine实现代码略*/public class TraficControlsystem { /*交通控制类*/private Vehicle[]V=new Vehicle[24];int numVehicles;public void control(){for {int i=0; i<numVehicles; i++){if(V[i]instanceof Emergency&&((Emergency)v[i]).isEmergent()){(______).runRedLight();}else______. run();}}void add(Vehicle vehicle){ v[numVehicles++]=vehicle;}/*添加车辆*/void shutDown(){/*代码略*/}public static void main(String[]args){TraficC0ntrolSystem tcs=new TraficControlSystem();tcs.add(new Car());tcs.add(new PoliceCar());tcs.add(new Ambulance());tcs.add(new Ambulance(true));tcs.add(new FireEngine(true));tcs.add(new Truck());tcs.add(new FireEngine());tcs.control();tcs.shutDown();}}


    答案:
    解析:
    boolean isEmergent()
    void runRedLight()
    extends Car implements Emergency
    this.isEmergency
    (Emergency)v[i]
    v[i]

  • 第3题:

    class A {  protected int method1(int a, int b) { return 0; }  }  Which two are valid in a class that extends class A?() 

    • A、 public int method1(int a, int b) { return 0; }
    • B、 private int method1(int a, int b) { return 0; }
    • C、 private int method1(int a, long b) { return 0; }
    • D、 public short method1(int a, int b) { return 0: }
    • E、 static protected int method1(int a, int b) { return 0; }

    正确答案:A,C

  • 第4题:

    Given the following code, which method declarations, when inserted at the indicated position, will not cause the program to fail compilation?()   public class Qdd1f {   public long sum(long a, long b) {  return a + b;  }   // insert new method declaration here  }  

    • A、public int sum(int a, int b) { return a + b; }
    • B、public int sum(long a, long b) { return 0; }
    • C、abstract int sum();
    • D、private long sum(long a, long b) { return a + b; }
    • E、public long sum(long a, int b) { return a + b; }

    正确答案:A,E

  • 第5题:

    10. abstract public class Employee {  11. protected abstract double getSalesAmount();  12. public double getCommision() {  13. return getSalesAmount() * 0.15;  14. }  15. }  16. class Sales extends Employee {  17. // insert method here  18. }  Which two methods, inserted independently at line 17, correctly complete the Sales class?()

    • A、 double getSalesAmount() { return 1230.45; }
    • B、 public double getSalesAmount() { return 1230.45; }
    • C、 private double getSalesAmount() { return 1230.45; }
    • D、 protected double getSalesAmount() { return 1230.45; }

    正确答案:B,D

  • 第6题:

    class One {   public One foo() { return this; }  }  class Two extends One {  public One foo() { return this; }  }  class Three extends Two {   // insert method here  }  Which two methods, inserted individually, correctly complete the Three class?()

    • A、 public void foo() { }
    • B、 public int foo() { return 3; }
    • C、 public Two foo() { return this; }
    • D、 public One foo() { return this; }
    • E、 public Object foo() { return this; }

    正确答案:C,D

  • 第7题:

    public class Parent {  public int addValue( int a, int b) {     int s;     s = a+b;     return s;     }     }  class Child extends Parent {  }  Which methods can be added into class Child?()   

    • A、 int addValue( int a, int b ){// do something...}
    • B、 public void addValue (){// do something...}
    • C、 public int addValue( int a ){// do something...}
    • D、 public int addValue( int a, int b )throws MyException {//do something...}

    正确答案:B,C

  • 第8题:

    class A {   public int getNumber(int a) {   return a + 1;   }   }    class B extends A {   public int getNumber (int a) {   return a + 2   }    public static void main (String args) {   A a = new B();   System.out.printIn(a.getNumber(0));   }   }   What is the result? () 

    • A、 Compilation succeeds and 1 is printed.
    • B、 Compilation succeeds and 2 is printed.
    • C、 An error at line 8 causes compilation to fail.
    • D、 An error at line 13 causes compilation to fail.
    • E、 An error at line 14 causes compilation to fail.

    正确答案:B

  • 第9题:

    1. public class Blip {  2. protected int blipvert(int x) { return 0; }  3. }  4. class Vert extends Blip {  5. // insert code here  6. }  Which five methods, inserted independently at line 5, will compile?()  

    • A、 public int blipvert(int x) { return 0; }
    • B、 private int blipvert(int x) { return 0; }
    • C、 private int blipvert(long x) { return 0; }
    • D、 protected long blipvert(int x, int y) { return 0; }
    • E、 protected int blipvert(long x) { return 0; }
    • F、 protected long blipvert(long x) { return 0; }
    • G、protected long blipvert(int x) { return 0; }

    正确答案:A,C,D,E,F

  • 第10题:

    单选题
    class A {   public int getNumber(int a) {   return a + 1;   }   }    class B extends A {   public int getNumber (int a) {   return a + 2   }    public static void main (String args) {   A a = new B();   System.out.printIn(a.getNumber(0));   }   }   What is the result? ()
    A

     Compilation succeeds and 1 is printed.

    B

     Compilation succeeds and 2 is printed.

    C

     An error at line 8 causes compilation to fail.

    D

     An error at line 13 causes compilation to fail.

    E

     An error at line 14 causes compilation to fail.


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

  • 第11题:

    多选题
    class One {   public One foo() { return this; }  }  class Two extends One {  public One foo() { return this; }  }  class Three extends Two {   // insert method here  }  Which two methods, inserted individually, correctly complete the Three class?()
    A

    public void foo() { }

    B

    public int foo() { return 3; }

    C

    public Two foo() { return this; }

    D

    public One foo() { return this; }

    E

    public Object foo() { return this; }


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

  • 第12题:

    多选题
    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,F
    解析: 暂无解析

  • 第13题:

    阅读以下说明和Java代码,填充程序中的空缺,将解答填入答题纸的对应栏内。

    【说明】

    某应急交通控制系统(TraficControIS,stem)在红灯时控制各类车辆(Vehicle)的通

    行,其类图如图6-1所示,在紧急状态下应急车辆在红灯时可通行,其余车辆按正常规

    则通行。

    下面的Java代码实现以上设计,请完善其中的空缺。

    【Java代码】

    abstract class Vehicle

    public Vehicle () { }

    abstract void run

    };

    interface Emergency {

    (1) ;

    (2) ;

    }

    class Car extends Vehicle {

    public Car () { }

    void run () { /*代码略*/ }

    };

    class Truck extends Vehicle {

    public Truck () { }

    void run () { /*代码略*/ }

    class PoliceCar (3)

    boolean isEmergency = false;

    public PoliceCar () { }

    public PoliceCar(boolean b) { this . isEmergency =b; }

    public boolean isEmergent () { return (4); }

    public void runRedLight () { /*代码略*/ }

    }

    /*类Ambulance. FireEngine实现代码略*/

    public class TraficControISystem {/。交通控制类。/

    private Vehicle[ ]V=new Vehiele [24];

    int numVehicles;

    public void control() {

    for (int i=0; i<numVehicles; i++) {

    if (v[i] instanceof Enu rgency&& ((Emergency)V [i])

    isEmergent()) {

    ( 5 ) . runRedLigh&39;: ( ) ;

    }else

    (6).run( )

    }

    }

    void add (Vehicle vehicle) { v[numVehicles++]=vehicle;)/*添加车辆*/

    void shutDown()(/*代码略*/}

    public static void main (Stri.ng [ ] args) {

    TraficControlSystem tcs = new TraficControlSystem() ;

    tcs . add (new Car () ;

    tcs .add (new PoliceCar () ;

    tcs .add (new Ambulance () ;

    tcs . add (new Ambulance (true》 ;

    tcs . add (new FireEngine ( true》 ;

    tcs . add (new Truck () ;

    tcs . add (new FireEngine ( ) ;

    tcs . control () ;

    tcs . shutDown () ;

    }

    }


    正确答案:
    本题考查Java语言程序设计的能力,涉及类、对象、方法的定义和相关操作。要求
    考生根据给出的案例和执行过程说明,认真阅读理清程序思路,然后完成题目。
    根据题目说明,以交通控制系统(Tn.ficControISystem)为背景,本题目中涉及的各
    类车辆和是否应急状态下在红灯时的通行情况。根据说明进行设计,题目给出了类图(图
    6-1类图所示)。
    图中父类Vehicle,代表交通工具,设计为抽象类。在Java用abstract关键字表示,
    表示行驶某一个具体的交通工具。Vehick包含一个抽象方法:run(),方法后没有实现,
    直接用;来表示抽象方法,表示行驶的方法由具体子类型完成,所以Vehicle的run()为一
    个抽象方法:
    Abstractvoidrun()
    Car和Truck都继承自Vehicle的两个子类型,所以他们都继承了Vehicle的run()方
    法,各自行驶方式有所不同,所以都覆盖了Vehicle的run()方法,并加以实现:
    voidrun(){/*代码略*/}
    Car的两个子类型PoliceCar和Ambuance都继承自Car,从而PoliceCar和Ambulance
    也都继承了Car中的run()方法。Truck的子类FireEngine也继承了Truck的run()方法。
    图6-1中Emergency在Java中采用接口实现,其中约定红灯时通行的相关接口为:
    isEmergent()和runRedLight().
    isEmergent()接口约定应急车辆返回自身紧急情况状态,用bool类型的isEmergency
    表示:this.isEmergency,其值在紧急情况下为true,非紧急情况下为false。mnRedLight()
    接口约定应急车辆在红灯时如何通行(isEmer:;ency为true,则通行,isEmergency为false,
    和普通车辆一样通行)。实现Emergency的类有PoliceCar、Ambulance和FireEngine,所
    以在这三个类中都要实现Emergency中定义的接口。在Java中,实现接口用implements
    关键字,后面加上所要实现的接口,即:
    ClassNameimplementsInterfaceName
    交通控制类TraficControISystem对运行的交通工具进行控制,所有交通工具用
    Vehicle数组v表示;numVehicles表示交通工具数量;control函数进行控制在紧急情况
    下应急车辆红灯通行,其他情况按常规通行;add()表示有车辆加入系统,shutDown()表示系统关闭。Vehicle的子类具体类型有Car、71ruck、PoliceCar、Ambulance和FireEngine,
    所以v[]数组中对象有这些类型的对象,加入v[]时会自动向上转型成为Vehicle类型,
    Emergency接口的应急车辆有runRedLight()方法,其他Car和Truck只有run()方法。因
    此,用for循环中对每个v[i],判定是否是Emergency类型的实例,即是否实现了
    Emergency。Java中判断一个对象是否是某个类型的实例用instanceof关键字。即:v[i]
    instanceofEmergency,如果是,说明是应急车辆,接着判定应急车辆的状态,在判定之
    前先要将应急车辆进行向下转型,Java中向]转型直接在对象前加上用括号括起来的转
    换的目标类型即可,即:[Emergency)vli]).isEmergent0,如果判定为真,执行
    runRedLight(),判定不成功,则调用run(),调用时动态绑定每个数组元素的实际类型,
    需要通过动态类型转换并调用runRedLight():
    if(v[i]instanceofEmergency&&《Emergency)v[i]).isEmergent()){
    ((Emergency)v[i]).runRedLight();
    }else
    V[i]->run();

    主控逻辑代码在maln有法中实现。初始化TraficControISystem,用tcs表示,调用
    tcs的add()函数添加具体的交通工具,这里会II动向上转型成为Vehicle类型,调用control()
    对各车辆进行控制,调用shutDown()系统关自闭
    因此,空(1)和空(2)需要定义接口sEmergent0和runRedLight0,题目代码中
    已经给出用分号结尾,所以空(1)和空(2)分别为"boolisEmergent()”和“void
    runRedLight()”;空(3)需要继承父类Car和实现接口Emergency,Java中继承采用extends
    关键字,即应填入“extendsCarimplementsE】aergency”;空(4)要返回应急车辆对象的
    状态,即填入“this.isEmergency”;空(5)剑:为动态类型转换后的对象(Emergency)v[il;
    空(6)处为普通车辆对象v[i]。
    答案
    (1)booleanisEmergent()
    (2)Voidrunredlight()
    (3)extendsCarimplementsEmergency
    (4)this.isEmergency
    (5)(Emergency)v[i]
    (6)v[i]

  • 第14题:

    1. class A {  2. public int getNumber(int a) {  3.     return a + 1;  4. }  5. }  6.    7. class B extends A {  8. public int getNumber (int a) {  9. return a + 2  10. }  11.    12. public static void main (String args[])  {  13. A a = new B();  14. System.out.printIn(a.getNumber(0));  15.    } 16. }     What is the result?()  

    • A、 Compilation succeeds and 1 is printed.
    • B、 Compilation succeeds and 2 is printed.
    • C、 An error at line 8 causes compilation to fail.
    • D、 An error at line 13 causes compilation to fail.
    • E、 An error at line 14 causes compilation to fail.

    正确答案:B

  • 第15题:

    Which are syntactically valid statement at// point x?()     class Person {     private int a;  public int change(int m){  return m;  }     }  public class Teacher extends Person {     public int b;  public static void main(String arg[]){     Person p = new Person();     Teacher t = new Teacher();    int i;  // point x     }    } 

    • A、 i = m;
    • B、 i = b;
    • C、 i = p.a;
    • D、 i = p.change(30);
    • E、 i = t.b.

    正确答案:D,E

  • 第16题:

    10. interface Foo { int bar(); }  11. public class Sprite {  12. public int fubar( Foo foo) { return foo.bar(); }  13. public void testFoo() {  14. fubar(  15. // insert code here  16.);  17. }  18. }  Which code, inserted at line 15, allows the class Sprite to compile?() 

    • A、 Foo { public int bar() { return 1; } }
    • B、 new Foo { public int bar() { return 1; } }
    • C、 newFoo() { public int bar(){return 1; } }
    • D、 new class Foo { public int bar() { return 1; } }

    正确答案:C

  • 第17题:

    10. public class SuperCaic {  11. protected static int multiply(int a, int b) { return a * b; }  12. }  and:  20. public class SubCalc extends SuperCalc {  21. public static int multiply(int a, int b) {  22. int c = super.multiply(a, b);  23. return c;  24. }  25. }  and:  30. SubCalc sc = new SubCalc();  31. System.out.println(sc.multiply(3,4));  32. System.out.println(SubCalc.multiply(2,2));  What is the result?()

    • A、 12 4
    • B、 The code runs with no output.
    • C、 An exception is thrown at runtime.
    • D、 Compilation fails because of an error in line 21.
    • E、 Compilation fails because of an error in line 22.
    • F、 Compilation fails because of an error in line 31.

    正确答案:E

  • 第18题:

    11. abstract class Vehicle { public int speed() { return 0; } }  12. class Car extends Vehicle { public int speed() { return 60; } }  13. class RaceCar extends Car { public int speed() { return 150; }}  ......  21. RaceCar racer = new RaceCar();  22. Car car = new RaceCar();  23. Vehicle vehicle = new RaceCar();  24. System.out.println(racer.speed() + “, „ + car.speed()  25. + “, “+ vehicle.speed());  What is the result?() 

    • A、 0, 0,0
    • B、 150, 60, 0
    • C、 Compilation fails.
    • D、 150, 150, 150
    • E、 An exception is thrown at runtime.

    正确答案:D

  • 第19题:

    public class Car {  private int wheelCount;  private String vin;  public Car(String vin) {  this.vin = vin;  this.wheelCount = 4;  }  public String drive() {  return “zoom-zoom”;  }  public String getInfo() {  return “VIN: “+ vin + “wheels: “+ wheelCount;  }  }  And:  public class MeGo extends Car {  public MeGo(String vin) {  this.wheelCount = 3;  }  }  What two must the programmer do to correct the compilation errors?()

    • A、 insert a call to this() in the Car constructor
    • B、 insert a call to this() in the MeGo constructor
    • C、 insert a call to super() in the MeGo constructor
    • D、 insert a call to super(vin) in the MeGo constructor
    • E、 change the wheelCount variable in Car to protected
    • F、 change line 3 in the MeGo class to super.wheelCount = 3;

    正确答案:D,E

  • 第20题:

    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

  • 第21题:

    多选题
    Which are syntactically valid statement at// point x?()     class Person {     private int a;  public int change(int m){  return m;  }     }  public class Teacher extends Person {     public int b;  public static void main(String arg[]){     Person p = new Person();     Teacher t = new Teacher();    int i;  // point x     }    }
    A

    i = m;

    B

    i = b;

    C

    i = p.a;

    D

    i = p.change(30);

    E

    i = t.b.


    正确答案: C,D
    解析: A:m没有被申明过,不能使用。 
    B:虽然b是类Teacher的public成员变量,但是在静态方法中不能使用类中的非静态成员。 
    C://a是类Person的private成员,在类外不能直接引用。 
    D://change(int m)方法是public方法,并且返回一个int型值,可以通过类的实例变量p引用并赋值给一个int型变量。 
    E://b是类Teacher的public成员变量,且是int型,可以通过类的实例变量t引用并赋值给一个int型变量

  • 第22题:

    单选题
    11. abstract class Vehicle { public int speed() { return 0; } }  12. class Car extends Vehicle { public int speed() { return 60; } }  13. class RaceCar extends Car { public int speed() { return 150; }}  ......  21. RaceCar racer = new RaceCar();  22. Car car = new RaceCar();  23. Vehicle vehicle = new RaceCar();  24. System.out.println(racer.speed() + “, „ + car.speed()  25. + “, “+ vehicle.speed());  What is the result?()
    A

     0, 0,0

    B

     150, 60, 0

    C

     Compilation fails.

    D

     150, 150, 150

    E

     An exception is thrown at runtime.


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

  • 第23题:

    单选题
    10. interface Foo { int bar(); }  11. public class Sprite {  12. public int fubar( Foo foo) { return foo.bar(); }  13. public void testFoo() {  14. fubar(  15. // insert code here  16.);  17. }  18. }  Which code, inserted at line 15, allows the class Sprite to compile?()
    A

     Foo { public int bar() { return 1; } }

    B

     new Foo { public int bar() { return 1; } }

    C

     newFoo() { public int bar(){return 1; } }

    D

     new class Foo { public int bar() { return 1; } }


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

  • 第24题:

    单选题
    1. class A {  2. public int getNumber(int a) {  3.     return a + 1;  4. }  5. }  6.    7. class B extends A {  8. public int getNumber (int a) {  9. return a + 2  10. }  11.    12. public static void main (String args[])  {  13. A a = new B();  14. System.out.printIn(a.getNumber(0));  15.    } 16. }     What is the result?()
    A

     Compilation succeeds and 1 is printed.

    B

     Compilation succeeds and 2 is printed.

    C

     An error at line 8 causes compilation to fail.

    D

     An error at line 13 causes compilation to fail.

    E

     An error at line 14 causes compilation to fail.


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