中兴Java开发笔试试题附答案

上传人:送你****花 文档编号:185226077 上传时间:2021-07-04 格式:DOC 页数:28 大小:65.50KB
返回 下载 相关 举报
中兴Java开发笔试试题附答案_第1页
第1页 / 共28页
中兴Java开发笔试试题附答案_第2页
第2页 / 共28页
中兴Java开发笔试试题附答案_第3页
第3页 / 共28页
中兴Java开发笔试试题附答案_第4页
第4页 / 共28页
中兴Java开发笔试试题附答案_第5页
第5页 / 共28页
点击查看更多>>
资源描述

《中兴Java开发笔试试题附答案》由会员分享,可在线阅读,更多相关《中兴Java开发笔试试题附答案(28页珍藏版)》请在金锄头文库上搜索。

1、中兴Java开发笔试试题及答案1.类A,B和C的定义如下:public class A public void f() System.out.println(“A.f()”);public class B extends A public void f() System.out.println(“B.f()”);public class C public void g(A a) System.out.println(“g(A a)”);a.f();public void g(B b) System.out.println(“g(B b)”);b.f();运行下面程序:C c = new C()

2、;A a = new B();c.g(a);输出的结果是:()。A. g(A a)A.f()B. g(A a)B.f()C. g(B b)A.f()D. g(B b)B.f()正确答案:B2.执行下列语句:int a = 0x9af700; /1001 1010 1111 0111 0000 0000a = 2;变量a的值为:()。A. 0x26bdc00B. 0xc6bdc00C. 0x3fa0000D. 0x7e02ffff正确答案:A3.下列代码的输出结果是()。int j=0;for(int i=0;i100;i+)j=j+;System.out.println(j);A.0B.99C

3、.100D.101正确答案:A4.请看下列代码:public static void main(String args) set.add(new Integer(2);set.add(new Integer(1);System.out.println(set);如果想保证程序的输出结果是1,2,那么处应填入的代码是()。A.Set set = new TreeSet();B.Set set = new HashSet();C.Set set = new SortedSet();D.Set set = new LinkedHashSet();正确答案:A5.列代码的运行结果是()。public

4、class Forest implements Serializable private Tree tree = new Tree();public static void main(String args) Forest f = new Forest();try FileOutputStream fs = new FileOutputStream(“Forest.ser”);ObjectOutputStream os = new ObjectOutputStream(fs);os.writeObject(f);os.close(); catch (Exception ex) ex.print

5、StackTrace();class Tree A.编译失败B.运行时,抛出异常C.Forest的实例被序列化到文件D.Forest的实例和Tree的实例都被序列化到文件正确答案:B6. 请看下列代码:class Payload private int weight;public Payload(int wt) weight = wt;public Payload() public void setWeight(int w) weight = w;public String toString() return Integer.toString(weight);public class Test

6、Payload static void changePayload(Payload p) public static void main(String args) Payload p = new Payload();p.setWeight(1024);changePayload(p);System.out.println(“The value of p is ” + p);假设运行后输出“The value of p is 420”,那么处应填入代码是:A. p.setWeight(420);B. Payload.setWeight(420);C. p = new Payload(420);D

7、. p = new Payload();p.setWeight(420);正确答案:A7. 题目代码实现的功能是:把放入到TreeSet集合中的Student进行排序,首先按照num升序,如果num相同,再按照name降序。请问插入代码1和插入代码2处应填入的代码分别是:public class SortStudent public static void main(String args) TreeSet set=new TreeSet();set.add(new Student(19,”tom”);set.add(new Student(20,”jessica”);set.add(new

8、Student(19,”terry”);class Student implements 插入代码1private int num;private String name;public Student(int num,String name)this.name=name;this.num=num;插入代码2A. Comparablepublic int compareTo(Object o) Student stu=null;if(o instanceof Student)stu=(Student)o;int result=this.numstu.num?1:(this.num=stu.num

9、?0:-1);if(result=0)result=pareTo(stu.name);return result;B. Comparablepublic int compareTo(Object o) Student stu=null;if(o instanceof Student)stu=(Student)o;int result=this.numstu.num?1:(this.num=stu.num?0:-1);if(result=0)result=pareTo(this.name);return result;C. Compartorpublic int compare(Object o

10、) Student stu=null;if(o instanceof Student)stu=(Student)o;int result=this.numstu.num?1:(this.num=stu.num?0:-1);if(result=0)result=pareTo(stu.name);return result;D. Compartorpublic int compare(Object o) Student stu=null;if(o instanceof Student)stu=(Student)o;int result=this.numstu.num?1:(this.num=stu

11、.num?0:-1);if(result=0)result=pareTo(this.name);return result;正确答案:B8.下列语句创建对象的总个数是:()。String s=”a”+”b”+”c”+”d”+”e”;A.1B.2C.3D.4正确答案:A9. 下列代码的输出结果是:public static void main(String args) BigDecimal d1 = new BigDecimal(“3.0);BigDecimal d2 = new BigDecimal(“2.9);BigDecimal d3 = d1.subtract(d2);System.ou

12、t.println(d3);A. 0B. 0.1C. 0.10000000000000009D. 0.10正确答案:B10.运行下面程序:public class Foopublic static void main(String args) try test();System.out.println(“condition 1); catch (ArrayIndexOutOfBoundsException e) System.out.println(“condition 2); catch (Exception e) System.out.println(“condition 3); fina

13、lly System.out.println(“finally”);public static void test() String str = “cc”;pareTo(“abc”);输出的结果是:()。A.condition 1finallyB.condition 2finallyC.condition 1condition 3finallyD.condition 1condition 2finally正确答案:A11. 关于下列代码说法正确的是:public class A private int counter = 0;public static int getInstanceCount() return counter;public A() counter+;public static void main(String args) A a1 = new A();A a2 = new A();A a3 = new A();System.out.println(A.getInstanceCount();A. 该类编译失败B. 输出:1C. 输出:3D. 输出:0正确答案:A12. 运行下列代码发生的异常或错误是:public class ClassB public void count(int i) count(+i);public static void m

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 资格认证/考试 > 网络工程师认证 > 思科认证

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号