




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
武 汉 大 学 计 算 机 学 院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.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后,结果是:()。A. 在语句v= c;处产生编译时错误B. 在语句v= c;处产生运行时错误C. 输出:Vehicle: driveD. 输出:Vehicle: driveCar: driveCar: driveCar: driveVehicle: drive3、下列代码中的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 4)?99.9:9); A、输出结果为value is 99.99 B、输出结果为value is 9 C、输出结果为value is 9.0 D、编译错误7、下列代码的执行结果是:public class Test4 public 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、ababcc B、464688 C、46abc8 D、10abc88、以下程序的功能是:如果本月的第一天是星期一,随机产生本月某一天的日期(131之间),并显示该天是星期几。在下列程序段中填入正确的语句 import java.math.*; public class Statementpublic static void main(String args) int date=(int)(Math.random ()*30)+1;_case 0:System.out.println(本月+date+日是星期天);break;case 1:System.out.println(本月+date+日是星期一);break;case 2:System.out.println(本月+date+日是星期二);break;case 3:System.out.println(本月+date+日是星期三);break;case 4:System.out.println(本月+date+日是星期四);break;case 5:System.out.println(本月+date+日是星期五);break;case 6:System.out.println(本月+date+日是星期六);break;A、Switch(date%7) B、switch(date/7) C、switch(date%7) D、Switch(date/7)9、关于下列程序的功能,说法正确的是public class ko10_1 extends Thread int n;ko10_1() Thread td=new Thread(this);td.start();public void run()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 B、这段程序的功能是:每隔1秒打印012345 C、这段程序的功能是:每隔半秒打印012345 D、这段程序的功能是:每隔半分钟打印01234510、下面关于applet的说法中,不正确的是A、applet能够嵌入到HTML页面中 B、applet自身可以运行,也可以嵌入在其他应用程序中运行 C、applet是能够在浏览器中运行的Java类 D、applet与application的主要区别在于执行方式上不同二、程序阅读题(2小题20分)1、读程序,要求:i)描述程序功能;ii)写出输出结果。源程序User21.java的内容为:import java.io.*;public class User21public static void main(String args)System.out.println(Begin:);Filef=new File(c:/jdk15);if( f.exists() )show(f);System.out.println(End.);public static void show(File tree)inti;Filef;Stringfiles;files=tree.list();for(i=0; ifiles.length; i+)f=newFile( tree.toString()+/+filesi );if( f.isFile() )System.out.println(file +f);if( f.isDirectory() )System.out.println(directory +f);2、读程序,要求:i)描述程序功能;ii)写出输出结果。源程序User22.java的内容为:public class User22 extends Threadintcnt= 10;Stringmsg = Hello;static String lock=lock;public User22(int c,String m)cnt = c;msg = m;public static void main( 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+)trySystem.out.println(msg+i);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 implements Carintnum;public Demo32(int k)super(k);num = 10*k;public Final void main(String args )Carxp = new Demo32(101);System.out.paint(“xp.num = “+xp.num);3、分析程序结构,要求:i)写出改正错误后的完整程序。public class Demo33 implements Runnablepublic static void main()Demo33 mo = new Demo33( );intx1=10, x2=4, y;y = mo.add(x1,x2);y = mo.add(x1,x2*1.1);System.out.println(“y=” + y + “ “ + add(1.2,x1) );int add(int a,int b)return (a+b);private int add(int a,double b=0.0)return (a+b);四、程序编写题(3小题30分)1、写一个application程序,实现计算多种图形面积之和,并输出。具体要求:i) 设计一个抽象类Shape,包含一个不带参数、返回类型为double的方法area();ii) 分别设计Shape类的非抽象子类:圆形Circle,正方形Square,矩形Rectangle。(分别设置圆的半径、正方形边长、矩形的底边长和高,实现方法area())iii) 在main()方法中,先定义一个Shape对象数组,数组名arr,有3个数组元素,分别初始化为圆形、正方形、矩形的对象。然后计算arr数组各个元素的面积。最后输出每个图形的面积,输出所有面积之和。2、写一个applet程序。具体要求:i
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年垃圾分类测试试题及答案
- 2025年幕墙工人考试题目及答案
- 清朝四川状元试题及答案
- 2025年品德电子考试试题及答案
- 2025广东惠州市博罗县东部自来水有限公司招聘及模拟试卷及答案详解(有一套)
- 中药药士考试试题及答案
- 九十年纪念日活动策划方案
- 临湘市装修施工方案
- 2025内蒙古工业大学招聘20名博士学位事业编制工作人员模拟试卷及答案详解(必刷)
- 泸州高一期末语文试卷及答案
- 伟星PPR培训课件
- 小学语文高段课标解读
- 排污许可证审核及环境应急管理服务方案投标文件(技术方案)
- 艺术展演活动策划公司简介范文
- 2025陕西氢能产业发展有限公司所属单位招聘(101人)笔试参考题库附带答案详解
- 《公路技术状况评定》课件-第一章 公路损坏分类与识别
- 烟花爆竹生产经营单位应急演练计划
- 高速公路机电系统运维技术规程编制说明
- 精神病症状学
- 2025-2030年中国制动片和制动衬片行业市场现状供需分析及投资评估规划分析研究报告
- 安检服务风险管理制度
评论
0/150
提交评论