第 1 页 共 6 页 武 汉 大 学 计 算 机 学 院 2008— 2009 学年 度 第一 学期 期 末 考 试 《 JAVA 程 序 设 计》 试 卷 A 专 业 : ___________ 学号: ____________ 姓 名 : _________ 总分:_________ 一、单项选择题(1 0 小题 2 0 分) 1、编译和运行下列代码后结果是:( ) public class Test { static int total = 10; public static void main (String args [ ] ) { new Test(); } public Test () { System.out.println("In test"); System.out.println(this); int temp = this.total; if (temp > 5) System.out.println(temp); } } A. 编译器报第2 行有错 B. 编译器报第9 行有错 C. 在标准输出上打印的内容中有数字 10 D. 通过编译,但是产生运行时错误 2、下列类分别在不同的文件中定义:( ) class Vehicle { public void drive() { System.out.println("Vehicle: drive"); } } class Car extends Vehicle { public void drive() { System.out.println("Car: drive"); } } public class Test { public static void main (String args []) { Vehicle v; Car c; v = new Vehicle(); c = new Car(); v.drive(); c.drive(); v = c; v.drive(); } } 编译和执行类 Test 后,结果是:( )。 第 2 页 共 6 页 A. 在语句v= c;处产生编译时错误 B. 在语句v= c;处产生运行时错误 C. 输出: Vehicle: drive D. 输出: Vehicle: drive Car: drive Car: drive Car: drive Vehicle: drive 3、下列代码中的 public void add(int a)方法在add(5)形式调用下产生什么输出?( ) public class Test { public void add(int a) { loop: for (int i = 1; i < 3; i++) { for (int j = 1; j < 3; j++) { if (a == 5) break loop; System.out.println(i * j); } } } } A. 运行时错误 B. 抛出ArrayIndexOutOfBoundsException 异常 C. 输出:1, 2, 2, 4 D. 没有输出 4、在JAVA 中,类 Animal 中的方法 printA( )定义如下: public void printA( ){ int a=10; int result=10%3; System.out.println(result); } 在类 Dog 中方法 printA( )定义如下: public void pri...