发布时间 : 星期二 文章JAVA期末考试试题及答案更新完毕开始阅读
二、填空题(每空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 10_ 3、public class Unchecked {
public static void main(String[] args) { try { method();
} catch (Exception e) { System.out.println(\ } finally {
System.out.println(\ } }
static void method() { try { wrench();
System.out.println(\
} catch (ArithmeticException e) { System.out.println(\ } finally {
System.out.println(\
}
System.out.println(\ }
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(\ System.out.println(\ }
static int calculate(int x[], int y) { for (int i = 1; i < x.length; i++) if (y < x.length)