《JAVA程序设计》期末考试试题 下载本文

内容发布更新时间 : 2024/9/20 2:51:12星期一 下面是文章的全部内容请认真阅读。

《JAVA程序设计》期末考试试题

一、选择题(4分/题,共10个,共40分)

1. 在Java语言中,下列哪个变量名是不正确的 ( )

(A) large (B) 2much (C) $money (D) _postCode 2. 关于抽象类下列哪个描述正确? ( )

(A). 抽象类不能包含抽象方法。 (B). 接口和抽象类是一回事。

(C). 抽象类不能实例化,即不能生成对象。 (D). 抽象类可以实例化对象。 3. 以下对封装的描述正确的是( )

(A) 只能对一个类中的方法进行封装,不能对属性性进行封装

(B) 如果子类继承了父类,对于父类中进行封装的方法,子类仍然可以直接调用 (C) 封装的意义不大,因此在编码时尽量不要使用

(D) 封装的主要作用在于对外隐藏内部实现细节,增强程序的安全性 4. 下面关于Applet的说法正确的是: ( ) A) Applet也需要main方法

B) Applet必须继承java.awt.Applet C) Applet能访问本地文件 D) Applet程序不需要编译

5.以下对继承的描述错误的是( )

(A) Java中子类只能继承单个父类。 (B) Java中子接口只能继承单个接口。 (C) Java中子类可以实现多个接口。 (D) 当实例化子类时会先实例化父类。

6.在使用super 和this关键字时,以下描述正确的是( )

(A) 在子类构造方法中使用super()显示调用父类的构造方法,super()必须写在子类构造方法的第一行,否则编译不通过

(B) super()和this()不一定要放在构造方法内第一行 (C) this()和super()可以同时出现在一个构造函数中

(D) this()和super()可以在static环境中使用,包括static方法和static语句块

7. 如果有一个对象myListener, 为了使myListener对象能够接受并处理来自于smallButton按钮对象的点击动作事件,myListener对象应该实现哪个接口? ( ) (A)ActionListener (B)ItemListener (C)MouseListener (D)WindowListener

8. 下列情况中,不会使线程返回所持有的对象锁的是( ) (A) 当synchronized()语句块执行完毕 (B) 当调用了线程的suspend()方法

(C) 当在synchronized()语句块中出现异常(exception) (D) 当持有锁的线程调用该对象的wait()方法

第 1 页 (共 4 页)

9.下列代码执行结果是什么? ( )

String s1 = \s1.concat(\

System.out.println(s1); (A) The string \(B) The string \(C) The string \(D) The string \

10. 当变量x是哪些值的时候输出包括\,选出最完整的答案? ( ) switch(x) { case 1 :

System.out.println(\ case 2 : case 3 :

System.out.println(\ case 4 :

System.out.println(\

}

(A) 3 (B) 1 或 2 或 3 或 4 (C) 1 或 2 或 3 (D) 4

二、 填空题(5分/空,共2个,共10分)

1.请简述String和StringBuffer的联系和区别。 2.请简述抽象类和接口的区别。

三、读程题 ( 5分/题,共6个,共30分)

1. 请写出以下程序的输出结果。

public class Demo{

public static void main(String[] args) { Integer a = new Integer(1); Integer b = new Integer(2); if(a==b)

System.out.println(“true”); else

System.out.println(“false”); }

}

2. 下面的代码执行结果是什么? public class TestThis{ private int i=0;

TestThis increment(){ i++;

return this; }

void print(){

System.out.println(i);

第 2 页 (共 4 页)

}

public static void main(String[] args){ TestThis x = new TestThis();

x.increment().increment().increment().print(); } } 3.下列程序输出什么?

class J {

static void swap(String s0, String s1) {

String s = s0; s0 = s1; s1 = s; }

public static void main(String args[]) {

String[] s = { \ swap(s[0], s[1]); System.out.println(s[0] + s[1]); } } 4. 读程序,写出正确的运行结果。

public class test { static int m = 9;

public static void main(String[] args) { test fd1 = new test(); fd1.m++;

test fd2 = new test();

System.out.println(fd1.m + “,” + fd2.m); } }

5. 阅读下列代码,写出运行结果。

public class Demo {

public static void main(String[] args) {

int i = 12;

System.out.println(i += i -= i *= i); } }

6. 阅读以下程序,写出运行结果。 class Q1{ public static void main(String args[ ]){ double d=1.23; Dec dec=new Dec( ); dec.decrement(d); System.out.println(d); }

第 3 页 (共 4 页)

classs Dec{ public void decrement(double decMe){ decMe = decMe - 0.1; } }

四. 阅读程序,回答问题。(20分)

如果有这样一个Java源文件如下,阅读程序,回答下面几个问题: public class Shelf{

public static void main(String[] arguments) { System.out.println(\ Book b = new Book(); b.get(); } }

class Book {

public void get() { System.out.println(\ } }

class Student {

public void read() { System.out.println (\ } }

(1) 请写出这个文件的完整名称(3分)

(2) 请写出在命令行上如何编译这个文件(3分) (3) 请写出这个文件编译后产生几个类文件(2分),它们的完整名称分别是什么?( (4) 请写出在命令行上如何运行这个程序?(2分) (5) 这个程序的运行结果是什么?(4分)

第 4 页 (共 4 页)

6分)