《面向对象程序设计JAVA语言程序设计》期末考试试题及部分答案解析 下载本文

内容发布更新时间 : 2024/5/18 4:16:41星期一 下面是文章的全部内容请认真阅读。

8.Java语言具有较好的安全性和可移植性及与平台无关等特性。 ( ) ( ) ( )

( )

9.Java语言的基本数据类型有4种:整型、浮点型、字符型和布尔型。 10.子类所继承父类的成员都可以在子类中访问。

11.Java语言规定在嵌套的程序块中不允许定义同名的成员变量。 12.Java语言采用16位颜色标准。Java的调色板保证128色。 13.静态方法只能处理静态变量。

( ) 14.画布(Canvas)是一种可容纳多个组件的容器。

15.Java语言是一种强类型语言,数据类型转换有两种:隐含转换和强制转换。 16.Java语言中,数组在静态和动态赋值时都判越界。

( )

17.Frame容器是有边框的容器,它也是一种独立窗口,只能作为最外层容器。 18.集合Set是通过键-值对的方式来存储对象的。 19.异常处理是在编译时进行的。

20.死锁的产生是因为多个线程间存在资源竞争。

四、阅读下列程序,请写出程序的输出结果 1.

class B { int b; B(int x) { b = x;

System.out.println(\

}

}

class A extends B { int a;

A(int x, int y) { super(x); a = y; System.out.println(\,a=\

}

( ) ( )

( )

( ) ( )

}

public class Test {

}

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

A obj = new A(13, 23);

答案 b=13 b=13,a=23 2.

public class Test1 { }

class AB { }

答案 Hello!I love JAVA. 3.public class Test {

public static void main(String[] args) { String s1; String s2;

AB(String str1, String str2) { }

public String toString() { }

return s1 + s2; s1 = str1; s2 = str2;

public static void main(String[] agrs) { }

AB s = new AB(\System.out.println(s.toString());

}

}

int[][] num1 = new int[2][3]; num1[0][0] = 3; num1[0][1] = 9; num1[0][2] = 60; num1[1][0] = 78; num1[1][1] = 79;

for (int i = 0; i <= 1; i++) { }

for (int j = 0; j < num1[i].length; j++)

System.out.print(num1[i][j] + \

System.out.println();

答案

3 9 60 78 79 0

4. public class Test {

public static void main(String[] agrs) { } 答案 s=30 s=90 s=180

int i, s = 0;

int a[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90 }; for (i = 0; i < a.length; i++) }

if (a[i] % 3 == 0) { }

s += a[i];

System.out.println(\

5. public class Test3 {

public static void main(String[] agrs) { }

} class A {

private int privateVar;

public A(int _privateVar) { boolean isEqualTo(A anotherA) { } } 答案 false

if (this.privateVar == anotherA.privateVar) else

return false;

return true;

privateVar = _privateVar;

}

A a = new A(2);

A b = new A(3);

System.out.println(a.isEqualTo(b));

6. public class Test {

public static void main(String[] args) {

int[][] num1 = new int[2][3]; num1[0][0] = 3; num1[1][0] = 78;

num1[0][1] = 9;

num1[0][2] = 45;

num1[1][1] = 79;

for (int i = 0; i <= 1; i++) { }

int[][] num2 = new int[][] { { 1, 2, 3 }, { 7, 8 } ,{ 9 } }; for (int i = 0; i

for (int j = 0; j < num1[i].length; j++)

System.out.print(num1[i][j] + \

System.out.println();