Java复习题2及答案 联系客服

发布时间 : 星期一 文章Java复习题2及答案更新完毕开始阅读67b4162e915f804d2b16c178

}finally{

System.out.print(\ } } }

public static void main(String []args) {

try{

aMethod(0);

}catch(Exception ex){

System.out.print(\ }

System.out.print(\ }

a) finally

exception in main finished

b) exception in main finally c) finally finished d) finished

exception in main finally

45、下面的异常处理代码的输出结果是()。 try{

int result = 6/0;

System.out.print(\,\ } catch(ArithmeticException e1) {

System.out.print(\异常,\ throw new Exception(); } catch(Exception e2) {

System.out.print(\异常,\ } finally {

System.out.print(\ }

A. 程序错误

B. ArithmeticException异常,finally

C. ArithmeticException异常, Exception异常, finally

D. try, ArithmeticException异常, Exception异常, finally

46、下列代码的输出结果是()。 public class Example {

String str = new String(\ char[] ch = {'a','b','c'};

public static void main(String[] args) { Example ex=new Example(); ex.change(ex.str,ex.ch);

System.out.print(ex.str+\ System.out.println(ex.ch); }

public void change(String str,char ch[]){ str=\ ch[0]='g'; } }

A. good and abc B. good and gbc C. test ok and abc D. test ok and gbc

47、阅读下面代码,将会输出()。 public class Testa {

Integer a = new Integer(10); Integer b = new Integer(10);

public static void main (String[ ] args){ Testa testA = new Testa(); if (testA.a==testA.b){

System.out.print(\很\ }

if (testA.a.equals(testA.b)){ System.out.print(\好\ } } }

48、关于Java的继承,下面说法错误的是()。(选择两项) A. 接口可以继承接口 B. 子类不可以继承父类的私有属性和私有方法 C. 所有类都是java.lang.Object的子类,但是不可以这样写:public class

Earth extends Object{}

D. 一个类不可以继承(extends)另一个类,同时又实现(implements)一个接口

49、阅读下面的代码,正确的说法是()。(选择两项) class Foo {

int num;

Baz comp = new Baz();

A. B. C. D. E.

50、try {}里有一个return语句,那么紧跟在这个try后的finally{}里的代码会不会被

执行,什么时候被执行?

A. 不会执行 B. 会执行,在return前执行 C. 会执行,在return后执行 D. 会执行,可能在return前执行,也可能在return后执行

}

class Bar {

boolean flag; }

class Baz extends Foo { Bar thing = new Bar(); double limit; }

Bar是Baz子类 Foo 包含 Bar Baz是Foo子类 Foo是Baz子类 Baz包含Bar