0, 0,0
150, 60, 0
Compilation fails.
150, 150, 150
An exception is thrown at runtime.
第1题:

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; }
第2题:
第3题:
class A { protected int method1(int a, int b) { return 0; } } Which two are valid in a class that extends class A?()
第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 }
第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?()
第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?()
第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?()
第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? ()
第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?()
第10题:
Compilation succeeds and 1 is printed.
Compilation succeeds and 2 is printed.
An error at line 8 causes compilation to fail.
An error at line 13 causes compilation to fail.
An error at line 14 causes compilation to fail.
第11题:
public void foo() { }
public int foo() { return 3; }
public Two foo() { return this; }
public One foo() { return this; }
public Object foo() { return this; }
第12题:
public class Circle implements Shape { private int radius; }
public abstract class Circle extends Shape { private int radius; }
public class Circle extends Shape { private int radius; public void draw(); }
public abstract class Circle implements Shape { private int radius; public void draw(); }
public class Circle extends Shape { private int radius;public void draw() {/* code here */} }
public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }
第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 () ;
}
}
第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?()
第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 } }
第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?()
第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?()
第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?()
第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?()
第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?()
第21题:
i = m;
i = b;
i = p.a;
i = p.change(30);
i = t.b.
第22题:
0, 0,0
150, 60, 0
Compilation fails.
150, 150, 150
An exception is thrown at runtime.
第23题:
Foo { public int bar() { return 1; } }
new Foo { public int bar() { return 1; } }
newFoo() { public int bar(){return 1; } }
new class Foo { public int bar() { return 1; } }
第24题:
Compilation succeeds and 1 is printed.
Compilation succeeds and 2 is printed.
An error at line 8 causes compilation to fail.
An error at line 13 causes compilation to fail.
An error at line 14 causes compilation to fail.