浙江工商大学java期末试卷2份(含答案)讲解
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)浙江工商大学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语言程序设计》期末考试试题答案与解析

《JAVA语言程序设计》期末考试试题及答案(应考必备题库)一、单选择题1、编译Java Application 源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为( )。
A. javaB. .classC. htmlD. .exe2、设 x = 1 , y = 2 , z = 3,则表达式 y+=z--/++x 的值是( )。
A. 3B. 3. 5C. 4D. 53、不允许作为类及类成员的访问控制符的是( )。
A. publicB. privateC. staticD. protected4、为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式为( )。
A. static void method( )B. public void method( )C. final void method( )D. abstract void method( )二、填空题1、开发与运行Java程序需要经过的三个主要步骤为编辑源程序、编译生成字节码和解释运行字节码。
2、在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码占用2字节内存空间,这样,无论是中文字符还是英文字符,都是占用2字节内存空间。
3、设 x = 2 ,则表达式 ( x + + )/3 的值是0 。
4、若x = 5,y = 10,则x < y和x >= y的逻辑值分别为true和false。
5、抽象(abstract) 方法是一种仅有方法头,没有具体方法体和操作实现的方法,该方法必须在抽象类之中定义。
最终(final)方法是不能被当前类的子类重新定义的方法。
6、创建一个名为 MyPackage 的包的语句是package MyPackage ; ,该语句应该放在程序的位置为:应该在程序第一句。
7、设有数组定义:int MyIntArray[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70}; 则执行以下几个语句后的输出结果是120。
Java期末考试题及答案(K12教育文档)

Java期末考试题及答案(word版可编辑修改)编辑整理:尊敬的读者朋友们:这里是精品文档编辑中心,本文档内容是由我和我的同事精心编辑整理后发布的,发布之前我们对文中内容进行仔细校对,但是难免会有疏漏的地方,但是任然希望(Java期末考试题及答案(word 版可编辑修改))的内容能够给您的工作和学习带来便利。
同时也真诚的希望收到您的建议和反馈,这将是我们进步的源泉,前进的动力。
本文可编辑可修改,如果觉得对您有帮助请收藏以便随时查阅,最后祝您生活愉快业绩进步,以下为Java期末考试题及答案(word版可编辑修改)的全部内容。
Java期末考试题一、简答题(共8个题,每题5分,共40分)java语言有哪些特点?(1)简单的Java最初是为对家用电器进行集成控制而设计的一种语言,因此它必须简单明了.Java的风格类似于C++,因而C++程序员初次接触Java语言,就会感到很熟悉。
从某种意义上讲,Java语言是C及C++语言的一个变种.Java摒弃了C++中容易引发程序错误的一些特性,如指针、结构、枚举以及内存管理等。
Java提供了丰富的类库,可以帮助我们很方便的开发Java程序。
(2)面向对象的面向对象可以说是Java最重要的特性,所以它支持继承、重载、多态等面向对象的特性。
Java 语言的设计是完全面向对象的,它不支持类似C语言那样的面向过程的程序设计技术。
(3)健壮的Java致力于检查程序在编译和运行时的错误。
Java也是一种强类型的语言,其类型检查比C++还要严格。
类型检查帮助我们检查出许多开发早期出现的错误。
Java自己负责内存管理,提供了垃圾内存回收机制,有效的避免了C++中最头疼的内存泄漏问题。
(4)安全的Java的安全性可从两个方面得到保证。
一方面,在Java语言里,删除了指针和释放内存等C++功能,避免了非法内存操作.另一方面,通过Java的安全体系架构来确保Java代码的安全性。
从一开始,Java就被设计成能够防范各种袭击,包括:禁止运行时堆栈溢出.例如,蠕虫等病毒常用的袭击手段;禁止在自己的处理空间之外破坏内存;未经授权禁止读写文件;许多安全特性相继不断的被加入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 语言作为一门重要的编程语言,被广泛应用于软件开发、移动应用、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期末考试题库及答案解析Java期末考试题库及答案解析一、选择题1. Java语言属于以下哪种类型的编程语言?A. 编译型语言B. 解释型语言C. 汇编语言D. 机器语言答案:B2. 下列哪个关键字用于定义Java类?A. classB. structC. interfaceD. enum答案:A3. Java中的main方法的返回类型是什么?A. voidB. intC. StringD. Object答案:B4. 以下哪个是Java的集合框架中的接口?A. ArrayListB. LinkedListC. SetD. HashMap答案:C5. Java中的异常处理机制使用哪个关键字来实现?A. tryB. catchC. finallyD. all of the above答案:D二、填空题1. Java语言是_________设计的,它具有跨平台的特性。
答案:James Gosling2. 在Java中,一个类可以继承另一个类的_______方法和变量。
答案:非私有3. Java的垃圾回收机制是用于_______内存的。
答案:自动管理4. Java中的_______关键字用于定义接口。
答案:interface5. Java中的_______关键字用于实现多态。
答案:override三、简答题1. 请简述Java语言的三大特性。
答案:Java语言的三大特性包括:面向对象、跨平台和网络编程。
2. 什么是Java的封装性,它有什么好处?答案:封装性是Java面向对象编程的核心概念之一,它允许将数据(属性)和操作数据的方法组合在一起,形成一个“对象”。
封装的好处包括数据隐藏、安全性提高和易于维护。
3. 请解释Java中的继承机制,并举例说明。
答案:Java中的继承机制允许一个类(子类)继承另一个类(父类)的属性和方法。
这使得代码复用变得简单,并且可以创建层次结构。
例如,一个名为“Animal”的类可以被“Dog”类继承,后者可以继承“Animal”的所有属性和方法,同时也可以添加自己的特定属性和方法。
JAVA语言程序设计期末考试试题及答案

J A V A语言程序设计期末考试试题及答案------------------------------------------作者------------------------------------------日期JAVA语言程序设计考试试题及部分答案一、单选题:(每题 分)下列各题✌)、 )、 )、 )四个选项中,只有一个选项是正确的,请将正确选项的标记写在题干后的括号内。
.下列语句序列执行后, 的值是☎ ✆。
♓⏹♦ ❍ ⏹ ♦♒♓●♏☎ ☎❍✆ ☎ ⏹✆ ✆ ✌✆ ✆ ✆ ✆ .设 ♓、 为♓⏹♦型变量名,♋ 为♓⏹♦型数组名,以下选项中,正确的赋值语句是☎ ✆。
✌✆ ♓ ♓ ✆ ♋☯ ✆ ♓ ✆ ♋☎✆ .☺♋❖♋语言的类间的继承关系是☎ ✆。
✌✆ 多重的 ✆ 单重的 ✆ 线程的 ✆ 不能继承.设有定义 ♓⏹♦ ♓ ,则执行以下语句后,♓ 的值为☎ ✆。
♓ ♓ ✌✆ ✆ ✆ ✆ .下列选项中,用于在定义子类时声明父类名的关键字是☎ ✆。
✌)♓⏹♦♏❒♐♋♍♏ ✆ ☐♋♍♋♑♏ ✆ ♏⌧♦♏⏹♎♦ ✆ ♍●♋♦♦.若已定义 ♌⍓♦♏☯ ⌧ ❝ 其中 ≤ ≤ ,则对⌧数组元素错误的引用是☎ ✆。
✌✆ ⌧☯ ✆ ⌧☯ ✆ ⌧☯ ✆ ⌧☯.下列语句序列执行后,♍♒ 的值是☎ ✆。
♍♒♋❒ ♍♒✌♍♒♓♐☎♍♒ ♍♒ ✆ ♍♒✌✆ ✌ ✆ ✆ ✆ .下列语句序列执行后,♓ 的值是☎ ✆。
♓⏹♦ ♓ ♓♐☎ ♓ ✆ ♓ ♏●♦♏ ✌✆ ✆ ✆ ✆ .下列语句序列执行后, 的值是☎ ✆。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 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是指。