当前位置:文档之家› JAVA期末考试题

JAVA期末考试题

教研室主任(签字)大连交通大学试卷2006~2007学年第1学期订线学院院长(系主任)(签字)课程Java程序设计(2006级)课程性质(□必修□专业限选)考试方式(□闭卷开卷)一、简答题(在每个小题的下面简要给出答案)(本大题共10小题,每小题2分,总计20分)1.1A)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方法可以用类名调用吗?答:5.abstract类中可以有非abstract方法吗?答:6.源文件中声明编写的类一定在同一包中吗答:7.子类在什么情况下可以继承父类的友好成员?答:8.一个线程执行完run方法后,进入了什么状态?答:9.一个处于新建状态的线程调用isAlive()方法返回的结果是什么?答:10.ServerSocket对象调用什么方法来建立服务器端的Socket对象?答:二、阅读理解题(请在指定位置写出答案,否则无效。

本大题共6小题,每小题10分,总计60分)1.请给出E 类中标记的【结果1】、【结果2】。

class B { 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();; //【结果1】 ;//【结果2】 } }2.请给出E 类中标记的【结果1】、【结果2】。

class A{ double f(double x,double y) { 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();,8)); //【结果1】 ,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 String[number+1]; int k=1;while(fenxi.hasMoreTokens()) { String temp=fenxi.nextToken(); s[k]=temp;k++; }if(index<=number) return s[index]; 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); ":"+s2); //【结果】 } }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(); ,33)); //【结果1】 a=new Student2004(); ,33)); //【结果2】 } }订线5.请给出E 类中标记的【结果1】、【结果2】。

import java.awt.*; import ;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(); ","+; //【结果1】 ; ; ;while( { }; //【结果2】 } }共4 页 第 2页6.请说出E类中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 byte[3];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();; //【结果1】;//【结果2】}catch(IOException e){}}}订线四、模板编程题(请按模板要求,在指定位置写出【代码】答案,否则无效。

本大题共2小题,每小题10分,总计20分))【代码1】:【代码2】:【代码3】:【代码4】:【代码5】:import java.awt.*;import ;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,length=0,n=0;String str="我非常喜欢1236" ;index=【代码1】 //str调用方法返回"1236"在str出现的位置length=【代码2】 //str调用方法返回str中字符的个数char c=【代码3】 //str调用方法返回str中的字符:'喜'String temp=【代码4】 //str调用方法返回字符串"1236"n=【代码5】 //将temp转化为int型数据。

;}}共4 页第3 页。

相关主题