浙江工商大学java期末试卷2份(含问题详解)

合集下载

java期末考试题及答案及解析

java期末考试题及答案及解析

java期末考试题及答案及解析一、选择题(每题2分,共20分)1. 下列哪个选项不是Java的基本数据类型?A. intB. floatC. doubleD. String答案:D解析:Java的基本数据类型包括整型(byte, short, int, long)、浮点型(float, double)、字符型(char)和布尔型(boolean)。

String是一个引用数据类型。

2. 在Java中,哪个关键字用于定义一个类?A. classB. interfaceC. enumD. struct答案:A解析:关键字class用于定义一个类,是Java面向对象编程的基础。

3. 下列哪个是Java的控制流程语句?A. if-elseB. try-catchD. package答案:A解析:if-else是条件语句,属于控制流程语句。

try-catch用于异常处理,import和package用于导入和声明包。

4. Java中,哪个方法用于获取字符串的长度?A. length()B. size()C. count()D. getLength()答案:A解析:String类中的length()方法用于返回字符串的长度。

5. 下列哪个选项是Java集合框架中接口?A. ArrayListB. LinkedListC. HashSetD. Collection答案:D解析:Collection是Java集合框架中的一个根接口,而ArrayList、LinkedList和HashSet是实现了Collection接口的具体类。

6. 在Java中,哪个关键字用于实现多态?B. abstractC. extendsD. implements答案:C解析:extends关键字用于继承,是实现多态的一种方式。

7. 下列哪个是Java的异常类型?A. RuntimeExceptionB. IOExceptionC. SQLExceptionD. All of the above答案:D解析:所有选项都是Java的异常类型,其中RuntimeException是运行时异常,IOException和SQLException是检查型异常。

浙江工商大学Java期末试卷及答案(B_2007_-2008)

浙江工商大学Java期末试卷及答案(B_2007_-2008)

浙江工商大学Java期末试卷及答案(B_2007_-2008)浙江工商大学2008 /2009学年第二学期考试试卷(B卷) 课程名称:Java语言程序设计基础(英) 考试方式:开卷完成时限:120分钟班级名称:学号:姓名:Part 1. Single selectionQ.1 Which of the following are NOT valid Java comments? (3 mark)A. // This is a comment.B. /* This is a comment. */C. /** This is a comment. */D. \* This is a comment. *\Answer:Q.2 Which of the following methods cause the String object referenced by s to be changed? (3 mark)A. s.concat()B. s.toUpperCase()C. s.replace()D. None of the above.Answer:Q.3 Which of the following is not a wrapper class? (3 mark)A. StringB. IntegerC. BooleanD. CharacterAnswer:Q.4 Given non-static classes Outer and Inner where Inner is declared as an inner class of Outer, how is an instance of outer accessed from within the scope of Inner? (3 mark)A. thisB. this.OuterC. Outer.thisD. this.thisAnswer:Q.5 In order for the MyProgram program to be compiled and run, which of the following must be true? (3 mark)A. the MyProgram class must be defined in MyProgram.javaB. MyProgram must be declared public.C. My program must have a correctly formed main() method.D. MyProgram must import /doc/b11765283.html,ng.Answer:Q.6 Which of the following are true? (3 mark)A. The Thread class does not inherits the wait() and notify() methods.B. the Object class declares the wait() and notify() methods.C. Only the Synchronized class supports the wait() and notify() methods.D. The wait() and notify() methods have been deprecated in JDK1.2.Answer:Q.7 Which declares an abstract method in an abstract Java class? (3 mark)A. public abstract method();B. public abstract void method();C. public void abstract Method();E. public abstract void method() {}Answer:Q.8 Which of the following modifiers may NOT be used with a top-level class? (3 mark)A. publicB. privateC. abstractD. finalAnswer:Q.9 What is the output of the following program when it is invoked using the command line “java Test this is a test”? (3 mark)class Test {public static void main(String [] args){System.out.println(args[1]);}}A. thisB. isC. aD. testAnswer:Q.10 Which is NOT the example of polymorphism? (3 mark)A. Inner classesB. UpcastingC. Method overloadingD. Method overridingAnswer:Part 2. Read the program and write down the result Q.11 Please write down the output: (5 mark)public class Question {String s = “Outer”;public static void main (String [] args){S2 s2 = new S2();s2.display();}}class S1 {String s = “S1”;void display() {System.out.println(s);}}class S2 extends S1 {String s = “S2”;}Answer:Q.12 Please write down the output: (5 mark) public class Outer {String s = “Outer”;public static void main (String [] args){new Outer().new Inner();}Outer () {System.out.print(s);}class Inner {String s = “Inner”;Inner() {System.out.print(s);}}}Answer:Q.13 Please write down the output: (5 mark)import java.util.*;public class Question {public static void main (String args[]){TreeMap map = new TreeMap();map.put(“one”, “1”);map.put(“two”, “2”);map.put(“three”, “3”);displayMap(map);}static void displayMap(TreeMap map) {Collection c = map.entrySet();Iterator i = c.iterator();while(i.hasNext()) {Object o = i.next();System.out.print(o.toString());}}}Answer:Q.14 Please write down the output of the program (5 mark) public class Question {public static void main (String[] args){int i = 1;int j = 2;outer: while (i < j) {++i;inner: do {++j;if(j % 3 == 0) continue outer;if(i % 3 == 0) break inner;if(i % 3 == 1) break outer;System.out.println(i * j);} while (j < i);System.out.println(i + j);}}}Answer:Q.15 Please write down the output: (5 mark) public class Question {static int i = 1;static { ++i; }public static void main (String[] args){ increment (i, 5);display(i);}static void increment(int n, int m) {n+=m;}static void display (int n) {System.out.print(n);}static {++i;}}Answer:Q.16 Please write down the output: (5 mark) class ValHold{ public int i = 10;}public class ObParm{public static void main(String argv[]){ ObParm o = new ObParm();o.amethod();}public void amethod(){int i = 99;ValHold v = new ValHold();v.i=30;another(v,i);System.out.println(v.i);}public void another(ValHold v, int i){i=0;v.i = 20;ValHold vh = new ValHold();v = vh;System.out.println(v.i+ " "+i);}}Answer:Q.17 Please write down the output: (5 mark) public class Computation extends Thread{ private int num;private boolean isComplete;private int result;public Computation(int num){this.num = num;}public synchronized void run(){result = num*2;isComplete = true;notify();}public synchronized int getResult(){while(!isComplete){try{wait();}catch(InterruptedException e){}}return result;}public static void main(String[] args){ Computation[] computations = new Computation[4]; for(int i=0; i<="" p="">computations[i] = new Computation(i); computations[i].start();}for(Computation c:computations)System.out.print(c.getResult()+” “);}}Answer:Q.18 Please write down the output: (5 mark)import java.util.*;public class Question {public static void main (String args[]) {String s1 = “abc”;String s2 = “def”;Stack stack = new Stack();stack.push(s1);stack.push(s2);try {String s3 = (String) stack.pop() +(String)stack.pop();System.out.println(s3);} catch(EmptyStackException e){System.out.println(“Caught Exception”);}}}Answer:Part 3. ProgrammingQ.19 Pleas fill in the blank so that the command line arguments are printed to the output stream. For example, if we run this program use “Java Test this is a test”, the output of the program will be “this is a test”. Assume that the class is in the package called pract. (6 mark) ____________________________________public class Test{public static void main(String[] args){for(________:args)out.print(________);}}Q.20 Please fill in the blank so that the following code compiles and runs, printing“catch1finnally1finally2” (9 mark)public class Test{void f(){ throw new_________________;}public static void main(String[] args)_______________Exception{Test t = new Test();try{t.f();}catch(_____________ e){try{throw______________;}catch(Exception ex){System.out.print(“catch1”);______________ ex;}finally{System.out.print(“finally1”);}}finally{System.out.print(“finally2”);System.exit(0);}}}Q.21 Physics programming often involves complex numbers. Please design a complex class to implement complex number addition and subtraction operation. The class prototype and the output of the program is given as following, please add code to complete the class. (15 mark) public class Complex{double real;double img;public Complex(double x,double y){// add code here;}public Complex(Complex comp){// add code here;}public Complex addComplex(final Complex comp){// add code here;}public static Complex autoIncrement(final Complex comp){ // add code here;}public Complex subComplex(final Complex comp){ // add code here;}public static void print(final Complex comp){ // add code here;}public static void main(String[] args){Complex x = new Complex(1,1);Complex y = new Complex(2,3);Complex.print(x); //1.0+1.0ix = x.addComplex(y);Complex.print(x); //3.0+4.0ix = x.subComplex(y);Complex.print(x); //1.0+1.0iComplex z = Complex.autoIncrement(x);Complex.print(z); //2.0+2.0i}}The output of the program should be:1.0+1.0i3.0+4.0i 1.0+1.0i 1.0+1.0i。

《JAVA语言程序设计》期末考试试题及答案2(应考必备题库)(K12教育文档)

《JAVA语言程序设计》期末考试试题及答案2(应考必备题库)(K12教育文档)

《JAVA语言程序设计》期末考试试题及答案2(应考必备题库)(word版可编辑修改)编辑整理:尊敬的读者朋友们:这里是精品文档编辑中心,本文档内容是由我和我的同事精心编辑整理后发布的,发布之前我们对文中内容进行仔细校对,但是难免会有疏漏的地方,但是任然希望(《JAVA语言程序设计》期末考试试题及答案2(应考必备题库)(word版可编辑修改))的内容能够给您的工作和学习带来便利。

同时也真诚的希望收到您的建议和反馈,这将是我们进步的源泉,前进的动力。

本文可编辑可修改,如果觉得对您有帮助请收藏以便随时查阅,最后祝您生活愉快业绩进步,以下为《JAVA语言程序设计》期末考试试题及答案2(应考必备题库)(word版可编辑修改)的全部内容。

《JA V A语言程序设计》期末考试试题及答案2(应考必备题库)一.判断题1.Java的源代码中定义几个类,编译结果就生成几个以.class为后缀的字节码文件。

(√)2.Java程序里,创建新的类对象用关键字new,回收无用的类对象使用关键字free。

(× ) 3.Java有垃圾回收机制,内存回收程序可在指定的时间释放内存对象. (×)4.构造函数用于创建类的实例对象,构造函数名应与类名相同,返回类型为void。

(×)5.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch 中的参数类型有父类子类关系,此时应该将父类放在后面,子类放在前面。

(√)6.拥有abstract方法的类是抽象类,但抽象类中可以没有abstract方法。

(√)7.Java的屏幕坐标是以像素为单位,容器的左下角被确定为坐标的起点。

(×)8.静态初始化器是在其所属的类加载内存时由系统自动调用执行。

(√ ) 9.在Java中对象可以赋值,只要使用赋值号(等号)即可,相当于生成了一个各属性与赋值对象相同的新对象。

(×)A.正确B.错误二.单项选择题1.Java application中的主类需包含main方法,以下哪项是main方法的正确形参?()A、 String argsB、String ar[]C、Char argD、StringBuffer args[]2.以下关于继承的叙述正确的是( )。

大学java期末试题及答案

大学java期末试题及答案

大学java期末试题及答案一、选择题1. 下列哪个选项是Java的关键字?A. classB. objectC. methodD. variable答案:A. class2. Java中,以下哪一个不是访问修饰符?A. publicB. privateC. staticD. protected答案:C. static3. 下列哪个选项是Java标准库中用于输入输出的类?A. BufferedReaderB. MathC. ArrayListD. File答案:A. BufferedReader4. 在Java中,以下哪种类型不属于基本数据类型?A. intB. booleanC. StringD. char答案:C. String5. 下面哪个选项是Java的循环语句?A. if-elseB. switch-caseC. forD. try-catch答案:C. for二、填空题1. 在Java中,使用关键字________来定义一个类。

答案:class2. 在Java中,使用关键字________来定义一个方法。

答案:public3. Java中的逻辑运算符"与"对应的符号是________。

答案:&&4. Java中的逻辑运算符"或"对应的符号是________。

答案:||5. 在Java中,使用关键字________来创建一个对象。

答案:new三、简答题1. 请简要解释Java中的多态性。

答案:Java中的多态性是指同一种类型的对象,由于其父类或接口的不同实现,可以表现出不同的行为。

通过多态性,可以提高代码的灵活性和可扩展性,简化了程序的设计和开发。

例如,将子类的对象赋值给父类的引用,可以通过父类的引用调用子类的方法。

2. 什么是Java中的异常处理机制?请简要说明异常处理的步骤。

答案:Java中的异常处理机制是一种用于处理程序运行过程中可能出现的错误情况的机制。

大学JAVA语言程序设计期末考试试题及答案

大学JAVA语言程序设计期末考试试题及答案

大学J A V A语言程序设计期末考试试题及答案Prepared on 22 November 2020《JAVA语言程序设计》期末考试试题及答案3(应考必备题库)一、单项选择题1、如下哪个是Java中的标识符()A、publicB、superC、3numberD、width2、如下哪个是Java中的标识符( )A、fieldnameB、superC、3numberD、#number3、已知如下定义:String s = "story"; 下面哪个语句不是合法的( )A、s += "books";B、s = s + 100;C、int len = ;D、String t = s + “abc”;4、如下哪个是Java中有效的关键字()A、nameB、helloC、falseD、good5、下面的代码段执行之后count的值是什么( )int count = 1;for (int i = 1; i <= 5; i++) {count += i;}、5 B、1 C、15 D、166、定义一个类,必须使用的关键字是( )A、publicB、classC、interfaceD、static7、定义一个接口必须使用的关键字是()A、publicB、classC、interfaceD、static8、如果容器组件p的布局是BorderLayout,则在p的下边中添加一个按钮b,应该使用的语句是()A、(b);B、(b,"North");C、(b,"South");D、(p,"North");9、声明并创建一个按钮对象b,应该使用的语句是()A、Button b=new Button();B、button b=new button();C、Button b=new b();D、(“确定”);10、Frame对象默认的布局管理器是()A、FlowLayoutB、BorderLayoutC、CardLayoutD、null11、下列哪一个import命令可以使我们在程序中创建输入/输出流对象()A、import .*;B、import .*;C、import .*;D、import .*;12、下面哪一个import命令可以为我们提供编写网络应用程序的类()A、import .*;B、import .*;C、import .*;D、import .*;13、如果需要从文件中读取数据,则可以在程序中创建哪一个类的对象()A、FileInputStreamB、FileOutputStreamC、DataOutputStreamD、FileWriter二、填空题1、如果将类MyClass声明为public,它的文件名称必须是()才能正常编译。

java期末考试题及答案解析

java期末考试题及答案解析

java期末考试题及答案解析一、选择题1. Java语言是一种:A. 编译型语言B. 解释型语言C. 编译型和解释型语言D. 汇编语言答案:C2. 下列哪个不是Java的基本数据类型?A. intB. floatC. doubleD. string答案:D3. Java中的main方法必须定义为:A. public static void main(String args[])B. private static void main(String args[])C. protected static void main(String args[])D. public static int main(String args[])答案:A二、填空题1. Java程序的执行入口是________。

答案:main方法2. Java语言支持的两种继承方式是单继承和________。

答案:接口继承3. 在Java中,用于定义常量的关键字是________。

答案:final三、简答题1. 简述Java语言的跨平台特性。

答案:Java语言的跨平台特性主要得益于Java虚拟机(JVM)的概念。

Java代码首先被编译成字节码,然后可以在任何安装了相应版本Java虚拟机的平台上运行。

这种“一次编写,到处运行”的特性使得Java程序可以在不同的操作系统和硬件平台上无缝运行。

2. 描述Java集合框架中List、Set和Map三者的区别。

答案:List是一个有序集合,允许元素重复;Set是一个不允许重复元素的集合,且无序;Map是一个键值对集合,每个键只能映射一个值,键不允许重复,但值可以重复。

四、编程题1. 编写一个Java程序,实现计算两个整数相加的结果。

```javapublic class SumCalculator {public static void main(String[] args) {int num1 = 10;int num2 = 20;int sum = num1 + num2;System.out.println("The sum is: " + sum);}}```2. 编写一个Java程序,实现对一个字符串进行反转。

java期末试题及答案文库

java期末试题及答案文库

java期末试题及答案文库Java 期末试题及答案文库Java 语言作为一门重要的编程语言,被广泛应用于软件开发、移动应用、Web 应用等领域。

在Java 学习过程中,期末考试是对学生掌握程度的重要检验。

为了帮助同学们更好地准备期末考试,本文将提供一个Java期末试题及答案的文库,供大家参考学习。

一、选择题1. 下面哪个选项代表Java中的访问修饰符?a. publicb. privatec. protectedd. all of the above答案:d2. Java 中的多态是指什么?a. 对象在运行时才能确定其类型b. 对象可以同时拥有多个类型c. 子类可以覆盖父类的方法d. 父类可以引用子类对象3. 下面哪个关键字用于声明一个常量?a. finalb. staticc. constantd. const答案:a二、填空题1. Java 中通过关键字____实现类与类之间的继承。

答案:extends2. Java 中,通过关键字_____定义一个抽象类。

答案:abstract3. 在Java中,______是一种重要的异常处理机制。

答案:try-catch三、代码题1. 编写一个Java类,实现一个计算器的功能,包括加法、减法、乘法和除法四种运算。

要求使用面向对象的思想,将每种运算封装成一个方法,并在主方法中进行调用。

public class Calculator {public int add(int num1, int num2) {return num1 + num2;}public int subtract(int num1, int num2) {return num1 - num2;}public int multiply(int num1, int num2) {return num1 * num2;}public double divide(int num1, int num2) {if (num2 != 0) {return (double) num1 / num2;} else {throw new ArithmeticException("除数不能为0"); }}public static void main(String[] args) {Calculator calculator = new Calculator();System.out.println("1 + 2 = " + calculator.add(1, 2));System.out.println("3 - 2 = " + calculator.subtract(3, 2));System.out.println("2 * 4 = " + calculator.multiply(2, 4));System.out.println("6 / 3 = " + calculator.divide(6, 3));}}```四、应用题1. 编写一个Java程序,实现一个简单的学生成绩管理系统。

JAVA语言程序设计期末考试试题及答案

JAVA语言程序设计期末考试试题及答案

J A V A语言程序设计期末考试试题及答案------------------------------------------作者------------------------------------------日期JAVA语言程序设计考试试题及部分答案一、单选题:(每题 分)下列各题✌)、 )、 )、 )四个选项中,只有一个选项是正确的,请将正确选项的标记写在题干后的括号内。

.下列语句序列执行后, 的值是☎  ✆。

♓⏹♦ ❍ ⏹ ♦♒♓●♏☎ ☎❍✆  ☎  ⏹✆ ✆ ✌✆  ✆  ✆  ✆ .设 ♓、 为♓⏹♦型变量名,♋ 为♓⏹♦型数组名,以下选项中,正确的赋值语句是☎  ✆。

✌✆ ♓  ♓   ✆ ♋☯  ✆ ♓   ✆ ♋☎✆  .☺♋❖♋语言的类间的继承关系是☎  ✆。

✌✆ 多重的 ✆ 单重的 ✆ 线程的 ✆ 不能继承.设有定义 ♓⏹♦ ♓   ,则执行以下语句后,♓ 的值为☎  ✆。

♓  ♓  ✌✆  ✆  ✆  ✆ .下列选项中,用于在定义子类时声明父类名的关键字是☎  ✆。

✌)♓⏹♦♏❒♐♋♍♏ ✆ ☐♋♍♋♑♏ ✆ ♏⌧♦♏⏹♎♦ ✆ ♍●♋♦♦.若已定义 ♌⍓♦♏☯  ⌧ ❝ 其中 ≤ ≤ ,则对⌧数组元素错误的引用是☎  ✆。

✌✆ ⌧☯ ✆ ⌧☯ ✆ ⌧☯ ✆ ⌧☯.下列语句序列执行后,♍♒ 的值是☎  ✆。

♍♒♋❒ ♍♒✌♍♒♓♐☎♍♒    ♍♒ ✆ ♍♒✌✆ ✌ ✆  ✆  ✆ .下列语句序列执行后,♓ 的值是☎  ✆。

♓⏹♦ ♓ ♓♐☎ ♓   ✆ ♓ ♏●♦♏ ✌✆  ✆  ✆  ✆ .下列语句序列执行后, 的值是☎  ✆。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

浙江工商大学2006 /2007学年第一学期考试试卷课程名称:Java程序设计考试方式:闭卷完成时限:120分钟班级名称:学号:姓名:一、选择题(每题2分,共30分)1、Java中main()函数的值是。

A、 StringB、intC、charD、void2、如下字串是Java中的标识符。

A、 fieldnameB、superC、3numberD、#number3、下面的代码段中,执行之后i 和j 的值是。

int i = 1;int j;j = i++;A、 1, 1B、1, 2C、2, 1D、2, 24、已知表达式int m[] = {0, 1, 2, 3, 4, 5, 6 };下面表达式的值与数组下标量总数相等。

A、 m.length()B、m.lengthC、m.length()+1D、m.length+15、当浏览器返回到新URL的包含applet 的页面时调用以下函数。

A、 init()B、start()C、stop()D、destroy()6、以下方法用于定义线程的执行体。

A、 start()B、init()C、run()D、main()7、如果类中的成员变量可以被同一包访问,则使用如下约束符。

A、 privateB、publicC、protectedD、final8、以下约束符可用于定义成员常量。

A、 staticB、finalC、abstractD、No modifier can be used9、下面方法与applet的显示无关。

A、 update()B、draw()C、repaint()D、paint()10、请问如下方法可以将MenuBar加入Frame中。

A、 setMenu()B、setMenuBar()C、add()D、addMenuBar()11、下面不是Java中的容器。

A、 ScrollPaneB、CanvasC、DialogD、Applet12、下面的程序段创建了BufferedReader类的对象in,以便读取本机d盘my文件夹下的文件1.txt。

File 构造函数中正确的路径和文件名的表示是。

File f=new File(填代码处);file=new FileReader(f);in=new BufferedReader(file);A) "1.txt" B) "d:\\my\\1" C) "d:\\my\\1.txt" D) "d:\ my\1.txt"13、有整型数组:int[] x={12,35,8,7,2};,则调用方法Arrays.sort(x)后,数组x中的元素值依次是。

A) 2 7 8 12 35 B) 12 35 8 7 2C) 35 12 8 7 2 D) 8 7 12 35 214、下面的程序段执行后输出的结果是。

StringBuffer buf=new StringBuffer("Beijing2008");buf.insert(7,"@");System.out.println(buf.toString());A) Beijing@2008B) @Beijing2008 C) Beijing2008@ D) Beijing#200815、.下面表达式可用得到x和y的最大值。

A) x>y?y:x B) x<y?y:x C) x>y?(x+y):(x-y) D) x==y?y:x;二、多选题(每题至少有一个正确答案,多选少选都不给分,每题2分,共10分)16、下面赋值语句是合法的。

A、float a = 2.0B、double b = 2.0C、int c = 2D、long d = 217、下面语句是创建数组的正确语句。

A、 float f[][] = new float[6][6];B、float []f[] = new float[6][6];C、float f[][] = new float[][6];D、float [][]f = new float[6][6];18、Java中如下约束符是正确的。

A、 privateB、publicC、protectedD、protect19. 下面事件监听器在Java中有事件适配器。

A、 MouseListenerB、KeyListenerC、ActionListenerD、WindowListener20、已知如下的命令执行 java MyTest a b c,语句是正确的。

A、 args[0] = "MyTest a b c"B、args[0] = "MyTest"C、args[0] = "a"D、args[1]= 'b'三、填空题(每空格2分,共20分)1. 创建类的对象时,使用运算符__________给对象分配内存空间。

2. 定义类的构造方法不能有返回值类型,其名称与____ _名相同。

3. Java语言中关键字___ __表示双精度类型。

4. 若有定义:float b={1.1f, 3.5f, 6.8f};,则b.length()的值是_______。

5.若有类定义:class B extends A{…}则类B是类A的______。

6.接口中的成员只有静态常量和______。

7. 在子类中使用关键字_______做前缀可调用被子类覆盖的父类中的方法。

8. 关键字______用于导入包中的类到程序中,供程序中使用。

9. Java语言中, 通常把可能发生异常的方法调用语句放到try块中,并用紧跟其后的_____块来捕获和处理异常。

10. 程序中实现多线程的方法有两种:继承_____类和实现Runnable接口。

四、阅读程序题(本大题2小题,每小题5分,共10分)1. (5分)1: import java.util.Arrays;2:3: public class SortArray {4: public static void main(String args[]) {5: String[] str = {"size", "abs","length","class"};6: Arrays.sort(str);7: for (int i=0; i<str.length; i++)8: System.out.print(str[i]+" ");9: }10: }(1)写出程序运行后的结果。

(2分)abs class length size(2)方法调用str[0].length()的返回结果是多少?(3分)2. (5分)定义类A和类B如下. (5分)class A{int a=1;double d=2.0;void show( ){System.out.println("Class A: a="+a +"\td="+d);}}class B extends A{float a=3.0f;String d="Java program.";void show( ){super.show( );System.out.println("Class B: a="+a +"\td="+d);}}(1) 若在应用程序的main方法中有以下语句:A a=new A();a.show();则输出的结果如何?(2分)(2) 若在应用程序的main方法中定义类B的对象b:A b=new B();b.show();则输出的结果如何?(3分)五、编程题(本大题3小题,每小题10分,共30分)1.编写一个程序用选择法对数组a[]={20,10,50,40,30,70,60,80,90,100}进行由大到小的排序。

2.使用socket编写一个服务器端程序,服务器端程序在端口8888监听,如果它接到客户端发来的"hello"请求时会回应一个"hello",对客户端的其他请求不响应。

3.编写一个应用程序,创建三个线程分别显示各自的时间。

答案一、选择题(每题2分,共30分)1、D2、 A3、C4、B5、B6、C7、D8、B9、B 10、B 11、B 12、C 13、A14、A 15、B二、多选题(每题至少有一个正确答案,多选少选都不给分,每题2分,共10分)1、B,C,D2、A,B,C,D3、A,B,C4、ABD5、CD三、填空题(共20分)1.new2.类3.double4. 35.子类6. 抽象方法7.super8. import9. catch 10. Thread四、阅读程序题(本大题2小题,每小题5分,共10分)1、(1) abs class length size (2) 42、1) Class A: a=1 d=2.0 (2) Class A: a=1 d=2.0 Class B: a=3.0 d=Java program.五、编程题(本大题3小题,每小题10分,共30分)1、import java.io.*;public class SelectSort{public static void main(String args[]){int a[]={20,10,50,40,30,70,60,80,90,100};int temp;for (int i=0; i<a.length-1;i++)for (int j=i+1; j<a.length ; j++){if (a[i]<a[j]) {temp=a[i];a[i]=a[j];a[j]=temp;}}for (int k=0;k<a.length ;k++){System.out.println("a["+k+"]:"+a[k]);}}}2、import java.io.*;import .*;public class HelloServer{public static void main(String args[]) throws IOException{ServerSocket server=null;server = new ServerSocket(8888);Socket ClientSocket = null;ClientSocket = server.accept();String line;BufferedReader is =new BufferedReader(new InputStreamReader(ClientSocket.getInputStream()));PrintWriter os = new PrintWriter(ClientSocket.getOutputStream());while (true){line = is.readLine();if (line.equals("hello")) {os.println("hello");os.flush();}}}}3、mport java.util.*;import java.text.*;class ThreeTimeThread extends Thread{public ThreeTimeThread(String str){super(str);}public void run(){while (true) {SimpleDateFormat formatter = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss z");Date currentTime = new Date();try {sleep(1000);}catch (Exception e) {}String dateString = formatter.format(currentTime);System.out.println(getName()+":"+dateString);}}public static void main(String args[]) throws Exception{new ThreeTimeThread("first").start();new ThreeTimeThread("second").start();new ThreeTimeThread("third").start();}}浙江工商大学2006 /2007学年第一学期考试试卷课程名称:Java程序设计考试方式:闭卷完成时限:120分钟班级名称:学号:姓名:一、选择题(每题2分,共30分)1、Java程序的执行过程中用到一套JDK工具,其中java.exe是指。

相关文档
最新文档