《《面向对象程序设计》由会员分享,可在线阅读,更多相关《《面向对象程序设计(6页珍藏版)》请在金锄头文库上搜索。
1、武汉大学计算机学院20082009 学年度 第一学期 期末考试 JAVA 程 序 设 计 试 卷 A专业: 学号: 姓 名: 总分:一、单项选择题(10 小题20分)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.
2、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 ar
3、gs ) Vehicle v;Car c;v = new Vehicle(); c = new Car();v.drive();c.drive();v = c;v.drive();编译和执行类Test后,结果是:()。A. 在语句v= c;处产生编译时错误B.在语句v= c;处产生运行时错误C. 输出: Vehicle: driveD. 输出: Vehicle: driveCar: driveCar: driveCar: driveVehicle: drive3、下列代码中的public void add(int a)方法在add (5)形式调用下产生什么输出?()public class T
4、est public void add(int a) loop: for (int i = 1; i 3; i+)for (int j = 1; j 4)?99.9:9); A、输出结果为value is 99.99B、输出结果为value is 9C、输出结果为value is 9.0D、编译错误7、下列代码的执行结果是:public class Test4public static void main(String args)int a=4,b=6,c=8;String s=abc;System.out.println(a+b+s+c); System.out.println();A、 a
5、babccB、 464688C、 46abc8D、 10abc88、以下程序的功能是:如果本月的第一天是星期一,随机产生本月某一天的日期(131 之间) 并显示该天是星期几。在下列程序段中填入正确的语句import java.math.*;public class Statementpublic static void main(String args) int date=(int)(Math.random ()*30)+1;case0:System.outcase1:System.outcase2:System.outcase3:System.outcase4:System.outcase5
6、:System.outcase6:System.out.println(本月+date+日是星期天).println(本月+date+日是星期一).println(本月+date+日是星期二).println(本月+date+日是星期三).println(本月+date+日是星期四).println(本月+date+日是星期五).println(本月+date+日是星期六)break;break;break;break;break;break;break;A、 Switch(date%7)B、 switch(date/7) C、switch(date%7) D、 Switch(date/7)9
7、、关于下列程序的功能,说法正确的是public class ko10_1 extends Threadint n;ko10_1() Thread td=new Thread(this);td.start();for (n=0;n6;n+) try System.out.print(n); Thread.sleep(500); catch(InterruptedException e) System.out.println(Exception); public static void main(String args) new ko10_1();A、这段程序的功能是:每隔500秒打印012345
8、B、这段程序的功能是:每隔1秒打印012345C、这段程序的功能是:每隔半秒打印012345D、这段程序的功能是:每隔半分钟打印01234510 、下面关于 applet 的说法中,不正确的是A、applet能够嵌入至IHTML页面中B、applet 自身可以运行,也可以嵌入在其他应用程序中运行C、applet 是能够在浏览器中运行的 Java 类D、applet与application的主要区另U在于执行方式上不同二、程序阅读题(2 小题 20 分)1、读程序,要求:i)描述程序功能;ii)写出输出结果。源程序User21java的内容为:import java.io.*;public cl
9、ass User21public static void main(String args) System.out.println(Begin:);File f=new File(c:/jdk15); if( f.exists() ) show(f); System.out.println(End.);public static void show(File tree) int i;File f;String files;files= tree.list();for(i=0; ifiles.length; i+)f = newFile( tree.toString()+/+filesi );i
10、f( f.isFile() )System.out.println(file +f);if( f.isDirectory() ) System.out.println(directory +f);2、读程序,要求:i)描述程序功能;ii)写出输出结果。源程序User22java的内容为: public class User22 extends Threadint cnt= 10;Stringmsg = Hello;static String lock=lock;public User22(int c,String m)cnt = c; msg = m;public static void ma
11、in( String args) System.out.println(Begin:);User22 x, y;x = new User22(1000,car );y = new User22(3000,dog );x.start();y.start();while(x.isAlive()|y.isAlive();System.out.println(End.);public void run() synchronized (lock)System.out.println(msg+start.); for(int i=0; i=3;i+)try System.out.println(msg+i
12、); this.sleep(cnt);catch(InterruptedException e) System.out.println(e); System.out.println(msg+end.);三、程序测试分析题(3 小题 30 分)1、分析程序结构,要求:i)写出改正错误后的完整程序。 public class Demo31 int n;public Final void main(str args) int i = 5; n = i*10;symatic.out.println(n= + n); 2、分析程序结构,要求:i)写出改正错误后的完整程序。 public class CarCar(int n) num = n; private int num; public class Demo32 imple