Java复习题2及答案(3)

2018-12-11 22:07

c) void aMethod(){}

d) private void aMethod();

38、下面的Java程序编译运行结果是() Interface A{ Int x=0;

}

Class B{ Int x=1; }

Class C extends B implements A{ Public void pX(){

System.out.println(super.x);

}

Public static voic main(String[] args){ New C().pX(); } }

a) 产生运行期错误 b) 产生编译期错误

c) 程序运行,输出结果为1 d) 程序运行,输出结果为0

39、分析如下Java代码,编译运行后将输出()。 public class Test{ public Test(){}

static void print(ArrayList al){ al.add(2);

al=new ArrayList(); al.add(3); al.add(4);

}

public static void main(String[]args){ Test test=new Test();

ArrayList al=new ArrayList(); al.add(1); print(al);

System.out.println(al.get(1)); } } a) 1 b) 2 c) 3 d) 4

(选择一项)

40、在Java中,关于构造方法,下列说法错误的是( ). (选择一项) A. 构造方法的名称必须与类名相同 B. 构造方法可以带输入参数 C. 构造方法不可以重载 D. 构造方法不能带返回参数

41、 给定如下所示的JAVA代码,则运行时,会产生( )类型的异常. (选择一项) String s=null; s.concat(\

A. ArithmeticException B. NullPointerException C. IOException

D. ClassNotFoundException

42、给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载 Public class Test {

Public void cal(int x,int y,int z)

{ } //A }

a) public int cal(int x,int y,float z){return 0;} b) public int cal(int x,int y,int z){return 0;} c) public void cal(int x,int z){}

d) public viod cal(int z,int y,int x){}

43、 在java中,已定义接口A,则以下语句正确的是().(选择二项)

a) class AAA extends A{} b) class AAA implements A{} c) interface AAA extends A{} d) interface AAA implements A{}

44、给定以下JAVA代码,这段代码编译运行后输出的结果是() (选择一项) public class Test {

public static int aMethod(int i) throws Exception { try{

return 10/i; //i=0时出现异常

}catch(Exception ex){

throw new Exception (\抛出异常

}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


Java复习题2及答案(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:企业员工差异化管理模式浅议

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: