《面向对象与 Java 程序设计》期末考试试题及答案
一、选择题(每道题只有一个正确答案,每小题2分,共30分)15道题
1、关于 Java 语言叙述错误的是:( C )
A.Java 语言具有跨平台性
B.Java 是一种面向对象的语言
C.Java 语言中的类可以多继承
D.Java 的垃圾收集机制自动回收程序已不再使用的对象
2、以下叙述正确的是:( B )的确台 a
A.构造方法必须是 public 方法
B.main 方法必须是 public 方法
C.Java 应用程序的文件名可以是任意的
D.构造方法应该声明为 void 类型
3、关于 Java 中数据类型叙述正确的是:( B )
A、整型数据在不同平台下长度不同
B.boolean 类型数据只有2个值,true 和 false
C.数组属于简单数据类型
D.Java 中的指针类型和 C 语言的一样
4、设 int x=1,float y=2,则表达式 x / y 的值是:( D )
A.0
B.1
C.2
D.以上都不是
5、以下语句有语法错的是:( A )
A.int x=1;y=2;z=3
B.for (int x=10,y=0;x>0;x++);
C.while (x>5);
D.for(; ;);
6、关于类和对象的叙述正确的是:( A )
A.Java 的类分为两大部分:系统定义的类和用户自定义的类
B.类的静态属性和全局变量的概念完全一样,只是表达形式不同
C.类的成员至少有一个属性和一个方法
D.类是对象的实例化
7、以下有关构造方法的说法,正确的是:( A )
A.一个类的构造方法可以有多个
B.构造方法在类定义时被调用
C.构造方法只能由对象中的其它方法调用
D.构造方法可以和类同名,也可以和类名不同
8、以下有关类的继承的叙述中,正确的是:( D )
A.子类能直接继承父类所有的非私有属性,也可通过接口继承父类的私有
属性
B.子类只能继承父类的方法,不能继承父类的属性
C.子类只能继承父类的非私有属性,不能继承父类的方法
D.子类不能继承父类的私有属性
9、下列属于容器的组件有:( B )
A.JButton
B.JPane
C.Canvas
D.JTextArea
10、void 的含义:( C )
A.方法体为空
B.定义的方法没有形参
C.定义的方法没有返回值
D.方法的返回值不能参加算术运算
11、关于 Java 中异常的叙述正确的是:( D )
A.异常是程序编写过程中代码的语法错误
B.异常是程序编写过程中代码的逻辑错误
C.异常出现后程序的运行马上中止
D.异常是可以捕获和处理的
12、所有的异常类皆继承哪一个类?( C )
A.java.io.Exception
B.java.lang.Throwable
C.java.lang.Exception
D.java.lang.Error
13、下面哪个不是 java 语言中的关键字?( B )
A.long
B.sizeof
C.instanceof
D.const
14、为实现进程之间的通信,需要使用下列那种流才合适?(D)
A.Data stream
B.File stream
C.Buffered stream
D.Piped stream
15、在复选框中移动鼠标,然后单击一选项,要捕获所选项必需实现哪个接口?
(D)
A.ActionListener
B.MouseListener
C.MouseMotionListern
D.ItemListener 二、填空题(每空1分,共20分)
1、面向对象程序设计所具有的基本特征是:___抽象性___,_封装性___,_继承
性__,_多态性__
2、数组 x 定义如下
int x[ ][ ]=new int[3][2]
则 x..length 的值为____3________,
x[0].length 的值为_____2_______。
3、Java 中实现多线程一般使用两种方法,一是___继承 Thread 类_________,二
是_____实现 Runnable 方法__________
4、Java 的图形用户界面设计中,有很多布局管理器用来摆放组件的位置,一般
用到的布局管理器有(列出四种即可)__FlowLayout_____,___GridLayout_____,
__BorderLayout_____,___CardLayout_______
5、Applet 常用的方法是:__init()_、__run()__、__stop()__和 destroy()。三、
阅读程序,写出程序的输出结果(每题5分,共20分)
1、class A{
private int privateVar;
A(int _privateVar){
privateVar=_privateVar;
}
boolean isEqualTo(A
anotherA){
if(this.privateVar == anotherA.privateVar)
return
true;
else
return false;
}
}
public class B{
public static void main(String args[]){
A a = new A(1);
A b = new A(2);
System.out.println(a.isEqualTo(b));
}
}程序的输出结果为:____false_____
2、class A {
double f(double x, double y) {
return x * y;
}
}
class B extends A {
double f(double x, double y) {
return x + y;
}
}
public class Test {
public static void main(String args[]) {
B obj = new B();
System.out.println("The program output is " + obj.f(4, 6));
}
}程序的输出结果为:__ The program output is 10_
3、public class Unchecked {
public static void main(String[] args) {
try {
method();
} catch (Exception e) {
System.out.println("A");
} finally {
System.out.println("B");
}
}
static void method() {
try {
wrench();
System.out.println("C");
} catch (ArithmeticException e) {
System.out.println("D");
} finally {
System.out.println("E");
}
System.out.println("F");
}
static void wrench() {
throw new NullPointerException();
}
}程序的输出结果为:
E
A
B
4、public class Test {
public static void main(String[] args) {
int x;
int a[] = { 0, 0, 0, 0, 0, 0 };
calculate(a, a[5]);
System.out.println("the value of a[0] is " + a[0]);
System.out.println("the value is a[5] is " + a[5]);
}
static int calculate(int x[], int y) {
for (int i = 1; i < x.length; i++)
if (y < x.length)
x[i] = x[i - 1] + 1;
return x[0];
}
}程序的输出结果为:
the value of a[0] is 0
the value is a[5] is 5