java期末考试试卷a.doc
-作者xxxx-日期xxxxjava期末考试试卷a【精品文档】一、 多项选择(每小题2分,共10分)1. JAVA语言是由【 】公司开发的A、 微软 B、sun C、IBM D、联想2. 以下描述错误的是【 】A、 JAVA能编写独立运行的应用程序B、 JAVA不支持多线程C、 JAVA是一网络应用软件D、 JAVA不能运行于windows 系统3. 程序中添加注释的作用是【 】A、使得程序运行更高效B、 增加程序的可读性C、增加程序的可理解性D、提高程序编译的速度4. 【 】文件A、 Hello.class B、Hello.java C、Hello.exe D、hello.jpx5. 对成员的访问控制保护最强的是【 】A、public B、缺省 C、 protectedD、 private二、 判断(每小题1分,共5分)1. 一个类可以生成多个对象,并且这些对象都具有相同的属性。( )2. java语言中不用区分字母的大写小写。( )3. 数组允许存放不同类型的定长元素。( )4. Java的类是单继承的,所有的类都从Object类派生而来的。( )5. System.out.println(“Hello java!”)是用来输出的。( )三、 填空(每空1分,共10分)1. 对象的状态和行为是对象的主要属性;前者对应类的 声明,行为又称为对象的操作,对应着类的 声明;2. 声明接口的保留字是 ;3. 类的声明“public class Test extends Applet implements Runnable”中,定义的类名是 ,其父类是 ,实现了 接口,这个类的源程序必须保存为 (写出包括扩展名的文件名);4. 一个完整的Java应用程序由一个或多个类组成;其中Java Application至少有一个主类,这个类中包含一个名为 的方法;5. 为了能使用Java中已提供的类,我们需要用 语句来引入所需要的类;语句import java.io.*; 中引入了 包的所有类;四、 程序分析(共45分)1. 阅读下列程序,然后回答问题。(10分)class Car private int carNumber; Car( ) Car(int no)this.carNumber=no; void setNumber(int carNum) carNumber = carNum; void showNumber() System.out.println(“My car No. is :” + carNumber); 写出这里定义了什么类?有哪些成员变量?有哪些成员方法? 有哪些构造方法?分别用来做什么? 这个类有无访问控制修饰?写出谁可以访问这个类内的属性和方法? void表示什么?2. 下列程序中,main( )方法中使用了上面定义的类,产生了多少个对象?对象名字分别是什么?写出执行后的输出结果。(5分)public class CarDemo public static void main(String args) Car demoCar1= new Car( ); demoCar1.setNumber(168168); demoCar1.showNumber( ); 3. 写出将字节数组转换为整数的程序代码(10分)4. 完善程序(10分)该程序功能为:求锥的体积,底可能为圆形或者梯形;interface com class tixing implements comprivate int sd,xd,h;tixing(int sd,int xd,int h)this.sd=sd;this.xd=xd;this.h=h;public double area( )return (sd+xd)*h*1/2;class round int r;round(int r)this.r=r;public double area( )return Math.PI*r*r; class zhuiprivate int h;private com c; zhui( )this.h=h;c=x; void huandi(com x)c=x; double squre( )return 1.0/3* *h;public class exampublic static void main(String args )zhui z; ;bottom=new tixing(2,7,10);z=new zhui(bottom,30);System.out.println(z.squre();bottom=new round(10);z.huandi(bottom);System.out.println(z.squre();5. 完善程序(10分)该程序功能为:两个线程,一个每隔1秒输出“A”,一个每隔2秒输出“B”,每个都输出20次。class mythread1 private int sleeptime=1000,num; mythread1(int num) public void run( ) int i; for (i = 0; i <= 19; i+) try ; catch (InterruptedException e) System.out.println("A"); System.out.println("End!"); class mythread2 extends Thread private int sleeptime=2000,num; mythread2(int num)this.num=num; public void run( ) int i; for (i = 0; i <= 19; i+) try sleep(sleeptime); catch (InterruptedException e) System.out.println("B"); System.out.println("End!"); public class test public static void main(String args ) mythread1 my1=new mythread1(1);Thread p1=new Thread(my1); ; ; p2.start( );五、 编程 (每题10分,共30分)1 将以下程序补充完整程序执行后输出结果为:初始点坐标为:3,4修改后点坐标为:5,6主类为:public class test1public static void main(String args ) test c=new test(3,4);System.out.print(“初始”);c.print( ); c.set(5,6);System.out.print(“修改后”); c.print( ); 2 已知钟表类和主类如下:class clockprivate int hour,minute;clock(int h,int m) hour=h;minute=m;void showc( )System.out.println(hour+”点”+minute+”分”);public class test2public static void main(String args)time tt=new time(2008,4,1,10,50);tt.show( );输出结果为:现在时间为2008-4-1 10点50分请将程序补充完整3 编写一个矩形类,长和宽从键盘输入,若输入的数据为负数则抛出自定义异常,并显示:长宽不合规则,否则求矩形的面积,并将结果写入a.txt文件中。【精品文档】