JAVA期末考试题.doc_第1页
JAVA期末考试题.doc_第2页
JAVA期末考试题.doc_第3页
JAVA期末考试题.doc_第4页
JAVA期末考试题.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

专 业班 级装订线学 号姓 名教研室主任(签字)学院院长(系主任)(签字)大连交通大学试卷20062007学年 第1学期课程 Java程序设计 (2006级)课程性质(必修专业限选) 考试方式(闭卷 开卷)阅卷人得 分一、简答题(在每个小题的下面简要给出答案)(本大题共10小题,每小题2分,总计20分)1 1下列哪个变量声明是错误的?A) int x=1234;B) char c=98;C) float d=12.89;D) byte m=12;答:2下列叙述哪些是正确的?A) final 类不可以有子类。B) abstract类中只能有abstract方法。C) abstract类中可以有非abstract方法,但该方法不可以用final修饰。D) 不可以同时用final和abstract修饰一个方法。答:3不同对象的实例变量分配的内存空间地址一定不同吗?答:4类的static方法可以用类名调用吗?答:5abstract类中可以有非abstract方法吗?答:6源文件中声明编写的类一定在同一包中吗答:7子类在什么情况下可以继承父类的友好成员?答:8一个线程执行完run方法后,进入了什么状态?答:9一个处于新建状态的线程调用isAlive()方法返回的结果是什么? 答:10ServerSocket对象调用什么方法来建立服务器端的Socket对象? 答:题 号一二三四五六七八总 分分 数阅卷人得 分二、阅读理解题(请在指定位置写出答案,否则无效。本大题共6小题,每小题10分,总计60分)1请给出E类中标记的【结果1】、【结果2】。class B1答:【结果1】:【结果2】: int n; static int sum=0; void setN(int n) this.n=n; int getSum() for(int i=1;i=n;i+) sum=sum+i; return sum; public class E public static void main(String args) B b1=new B(),b2=new B(); b1.setN(3); b2.setN(5); int s1=b1.getSum(); int s2=b2.getSum();System.out.println(s1); /【结果1】 System.out.println(s2);/【结果2】 2请给出E类中标记的【结果1】、【结果2】。class A double f(double x,double y)2答:【结果1】:【结果2】: return x+y; class B extends A double f(int x,int y) return x*y; public class E public static void main(String args) B b=new B(); System.out.println(b.f(5,8); /【结果1】 System.out.println(b.f(8.0,12.0);/ 【结果2】 考生注意: 考试时间100分钟 试卷总分 100 分 共 4 页 第 1 页专 业班 级装订线学 号姓 名3请给出E类中标记的【结果】。 import java.util.*;class GetToken String s; public String getToken(int index,String str) StringTokenizer fenxi=new StringTokenizer(str); int number=fenxi.countTokens(); s=new Stringnumber+1; int k=1; while(fenxi.hasMoreTokens() String temp=fenxi.nextToken(); sk=temp;3.答:【结果】: k+; if(index=number) return sindex; else return null; class E public static void main(String args) String str=public static void main; GetToken token=new GetToken(); String s1=token.getToken(2,str), s2=token.getToken(4,str); System.out.println(s1+:+s2); /【结果】 4.答:【结果1】:【结果2】:4请给出E类中标记的【结果1】、【结果2】。class AAA int add(int x,int y) return x+y; class Student2004 extends AAA int add(int x,int y) return x-y; public class E public static void main(String args) AAA a=new AAA(); System.out.println(a.add(55,33); /【结果1】 a=new Student2004(); System.out.println(a.add(55,33); /【结果2】 5请给出E类中标记的【结果1】、【结果2】。import java.awt.*;5答:【结果1】:【结果2】:import java.awt.event.*;public class E implements Runnable StringBuffer buffer=new StringBuffer(); Thread t1,t2,t3; E() t1=new Thread(this); t2=new Thread(this); t3=new Thread(this); public synchronized void addString(String c) if(Thread.currentThread()=t1) while(buffer.length()=0) try wait(); catch(Exception e) buffer.append(c); if(Thread.currentThread()=t2) while(buffer.length()15) try wait(); catch(Exception e) buffer.append(c); if(Thread.currentThread()=t3) buffer.append(c); notifyAll(); public void run() if(Thread.currentThread()=t1) addString(今天是一月十五号,) ; if(Thread.currentThread()=t2) addString(天气不错,) ; if(Thread.currentThread()=t3) addString(我们考试的科目是Java,) ; public static void main(String s) E hello=new E(); System.out.println(hello.t1.isAlive()+,+hello.t2.isAlive(); /【结果1】 hello.t2.start(); hello.t1.start(); hello.t3.start(); while(hello.t1.isAlive()|hello.t2.isAlive()|hello.t3.isAlive() System.out.println(hello.buffer); /【结果2】 共4 页 第 2 页专 业班 级装订线学 号姓 名6请说出E类中System.out.println的输出结果。6答:【结果1】:【结果2】:import java.io.*;public class E public static void main(String args) try FileOutputStream out=new FileOutputStream(hello.txt); FileInputStream in=new FileInputStream(hello.txt); byte content=ABCDEFG.getBytes(); StringBuffer bufferOne=new StringBuffer(),bufferTwo=new StringBuffer(); int m=-1; byte tom=new byte3; out.write(content); out.close(); while(m=in.read(tom,0,3)!=-1) String s1=new String (tom,0,m); bufferOne.append(s1); String s2=new String (tom,0,3); bufferTwo.append(s2); in.close(); System.out.println(bufferOne); /【结果1】 System.out.println(bufferTwo); /【结果2】 catch(IOException e) 阅卷人得 分 四、模板编程题(请按模板要求,在指定位置写出【代码】答案,否则无效。本大题共2小题,每小题10分,总计20分)1【代码1】: 【代码2】: 【代码3】:【代码4】: 【代码5】:import java.awt.*;import java.awt.event.*;class IenFrame extends Frame implements ActionListener TextField text; Label label; IenFrame() 【代码1】 /创建TextField对象:text,要求text的可见字符数为12个机器字符。 【代码2】 /创建 Label对象:label,要求label上的名字是I love this game。 【代码3】 /设置窗口的布局为FlowLayout型布局。 【代码4】 /将当前窗口作为text的ActionEvent事件的监视器。 add(label); add(text); public void actionPerformed(ActionEvent e) 【代码5】 /label调用方法将自己名字设置为text中的文本 2 【代码1】: 【代码2】: 【代码3】:【代码4】: 【代码5】:class IenString public static void main(String args) int index=-1

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论