0, 0,0
150, 60, 0
Compilation fails.
150, 150, 150
An exception is thrown at runtime.
第1题:
能将程序补充完整的选项是______。 class Person{ private int a; phblic 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; ______; } }
A.i=m
B.i=b
C.i=p.a
D.i=p.change(50)
第2题:
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; }
第3题:
class A
{public int getNumber(int a){return a+1;}}
class B extends A
{public int getNumber(int a, char c){return a+2;}public static void main(String[] args){B b=new B();System.out.println(b.getNumber(0));}}
what is the result?()
A.compilation succeeds and 1 is printed
B.compilation succeeds and 2 is printed
C.compilation succeeds and 3 is printed
D.An error at this program cause compilation to fail
第4题:
class A { protected int method1(int a, int b) { return 0; } } Which two are valid in a class that extends class A?()
第5题:
第6题:
使用VC6打开考生文件夹下的工程test17_1,此工程包含一个源程序文件test17_1.唧,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:
Vehicle message
Car message
Vehicle message
源程序文件test17_1.cpp 清单如下:
include <iostream.h>
class vehicle
{
int wheels;
float weight;
public:
/***************** found *****************/
void message(void){ cout<<"Vehicle message\n";}
};
class car:public vehicle
{
int passenger_load;
public:
/***************** found *****************/
void message (void){cout>>"Car message\n";}
};
class truck:public vehicle
{
int passenger_load;
float payload;
public:
int passengers(void){return passenger_load;}
};
void main()
{
vehicle * unicycle;
unicycle=new vehicle;
/***************** found *****************/
unicycle.message()
delete unicycle;
unicycle=new car;
unicycle->message();
delete unicycle;
unicycle=new truck;
unicycle->message();
delete unicycle;
}
第7题:
阅读以下说明和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 () ;
}
}
第8题:
能将程序补充完整的选项是( )。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; ______ }} B.
A.i=m
B.i=b
C. i=p.a
D.i=p. change(50)
第9题:
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?()
第10题:
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 } }