java试卷2006

更新时间:2023-11-14 11:08:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

大连交通大学试卷

2006~2007学年 第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方法可以用类名调用吗? 答:

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();

System.out.println(s1); //【结果1】 System.out.println(s2);//【结果2】 } }

1.答: 【结果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();

System.out.println(b.f(5,8)); //【结果1】 System.out.println(b.f(8.0,12.0));// 【结果2】 } }

2.答: 【结果1】: 【结果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++; }

3.答: if(index<=number) 【结果】: return s[index]; else return null; } } class E

{ public static void main(String args[]) 订

{ String str=\ GetToken token=new GetToken(); String s1=token.getToken(2,str), s2=token.getToken(4,str);

System.out.println(s1+\【结果】 } }

4.请给出E类中标记的【结果1】、【结果2】。

4.答: class AAA

{ int add(int x,int y) 【结果1】: { return x+y; 【结果2】: } 线

}

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.*;

import java.awt.event.*;

public class E implements Runnable 5.答: { StringBuffer buffer=new StringBuffer();

Thread t1,t2,t3;

【结果1】: E()

【结果2】: { 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()+\ //【结果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的输出结果。

import java.io.*; public class E {

public static void main(String args[]) { try{

专 业 班 级 6.答: 【结果1】: 【结果2】: FileOutputStream out=new FileOutputStream(\ FileInputStream in=new FileInputStream(\ byte content[]=\学 号 姓 名 StringBuffer bufferOne=new StringBuffer(),

装 int m=-1;

byte tom[]=new byte[3]; out.write(content); out.close();

while((m=in.read(tom,0,3))!=-1) {

bufferOne.append(s1);

String s2=new String (tom,0,3); bufferTwo.append(s2); 订

}

in.close();

System.out.println(bufferTwo); }

catch(IOException e){} } }

线

bufferTwo=new StringBuffer();

String s1=new String (tom,0,m);

System.out.println(bufferOne); //【结果1】 //【结果2】

本文来源:https://www.bwwdw.com/article/od1v.html

Top