java竞赛题库

上传人:第*** 文档编号:34017490 上传时间:2018-02-20 格式:DOCX 页数:11 大小:42.99KB
返回 下载 相关 举报
java竞赛题库_第1页
第1页 / 共11页
java竞赛题库_第2页
第2页 / 共11页
java竞赛题库_第3页
第3页 / 共11页
java竞赛题库_第4页
第4页 / 共11页
java竞赛题库_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《java竞赛题库》由会员分享,可在线阅读,更多相关《java竞赛题库(11页珍藏版)》请在金锄头文库上搜索。

1、一 单项选择题(3*15=45)1. 如下代码:public class JavaContest public static void main(String args) throwsException Thread.sleep(3000);System.out.println(alive);请问编译运行的结果是什么?A.编译出错B.运行时抛出异常C.程序运行大约 3 秒后输出:aliveD.程序运行大约 50 分钟后输出:aliveE.代码正常运行但没有输出2.如下代码:public class Test public Test() System.out.print(test);public

2、 Test(String val) this();System.out.print(test with +val );public static void main(String args) Test test = new Test(wow);请问编译运行的结果是什么?A. testB. test test with wowC. test with wowD. 编译失败3.代码片段:import java.io.*;public class Forest implements Serializable private Tree tree = new Tree();public static v

3、oid main(String args) Forest f = new Forest();try FileOutputStream fs = newFileOutputStream(Forest.Ser);ObjectOutputStream os = newObjectOutputStream(fs);os.writeObject(fs);os.close(); catch(Exception ex) ex.printStackTrace();class Tree 哪一项的描述是正确的?A. 编译出错B. 运行时抛出异常C. 一个 Forest 的实例被序列化了D. 一个 Forest 的

4、实例和一个 Tree 的实例都被序列化了4. 代码片段:public void aSafeMethod(Object value) /在这里检查方法的参数/这里省略其它代码System.out.println(value.toString();代码中的方法要求传入的参数是非空的,请问有什么比较好的方式去处理一个空值?A. assert value = null;B. if(value = null) throw new IllegalArgumentException(value can not be null);C. if(value = null) throw new AssertionE

5、xception(value can not be null);D. assert value != null : value can not be null;5. 给出如下代码片段:String elements = for,tea,too;String first = (elements.length 0) ? elements0 : null;以下哪个是正确结果?A. 编译失败B. 运行时抛出异常C. first 的值被设为 nullD. first 的值被设位”for”6.代码片段:public class Certkiller3 implements Runnable public

6、void run() System.out.print(running);public static void main(String args) Thread t = new Thread(new Certkiller3();t.run();t.run();t.start();执行的结果是?A. 编译出错B. 运行时抛出异常C. 代码正常执行并且输出:runningD. 代码正常执行并且输出:runningrunningE. 代码正常执行并且输出:runningrunningrunning7.代码片段:System.out.format(Pi is approximately %d, Mat

7、h.PI);请问执行的结果是什么?A. 编译出错B. Pi is approximately 3.C. Pi is approximately 3.141593.D. 运行时抛出异常8.如下代码:int i = 1;while (i != 5) switch (i+ % 3) case 0:System.out.print(A);break;case 1:System.out.print(B);break;case 2:System.out.print(C);break;请问编译运行的结果是什么?A. BCABB. BCBAC. ABCD. CBAE. NBAF. FIFA9.代码片段 1:p

8、ublic class ComplexCalc public int value;public void calc() value += 5; 代码片段 2:public class MoreComplexCalc extends ComplexCalc public void calc() value -= 2; public void calc(int multi) calc();super.calc();value *= multi;public static void main(String args) MoreComplexCalc calc = new MoreComplexCal

9、c();calc.calc(3);System.out.println(Oh it is: + calc.value);请问编译运行的结果是什么?A. Oh it is: 9B. 编译出错C. Oh it is: 15D. Oh it is: -6E. 代码正常运行但没有输出F. 运行时抛出异常G. Oh it is: 6H. Oh it is: -1510.代码片段:String text = Welcome to Java contest;String words = text.split(s);System.out.println(words.length);请问编译运行的结果是什么?A

10、. 0B. 1C. 4D. 编译出错E. 运行时抛出一个异常11.如下代码:public class Test private int a;public int b;protected int c;int d;public static void main(String args) Test test = new Test();int a = test.a+;int b = test.b-;int c = test.c+;int d = test.d-;System.out.println(a + - + b + - + c + - + d);请问哪个说法是正确的?A. 编译错误,因为变量 a

11、,b,c 和 d 没有被初始化B. 编译错误,因为变量 a 无法被访问C. 编译成功并输出 0 0 0 0D. 编译成功并输出 1 1 1 112.代码片段:import java.util.*;public class TestSet enum Num ONE, THREE, TWOpublic static void main(String args) Collection coll = new LinkedList();coll.add(Num.THREE);coll.add(Num.ONE);coll.add(Num.THREE);coll.add(Num.TWO);coll.add(

12、Num.TWO);Set set = new HashSet(coll);System.out.println(set);关于 set 变量的描述哪个选项是正确的?A. set 变量只包含了 coll 集合中的 3 个变量,并且顺序与 coll 里的相同。B. set 变量只包含了 coll 集合中的 3 个变量,但顺序无法确定。C. set 变量包含了 coll 集合中的 5 个变量,但顺序无法确定。D. set 变量包含了 coll 集合中的 5 个变量,并且顺序与 coll 里的相同。13.代码片段:public class Person private String name;publ

13、ic Person(String name) this.name = name; public boolean equals(Person p) return p.name.equals(this.name);哪个选项的描述是正确的?A. equals 方法没有正确覆盖 Object 类中的 equals 方法。B. 编译这段代码会出错,因为第 5 行的私有属性 p.name 访问不到。C. 如果要与基于哈希的数据结构一起正常地工作,只需要在这个类中再实现hashCode 方法即可。D. 当添加一组 Person 对象到类型为 java.util.Set 的集合时,第 4 行中equals 方

14、法能够避免重复。14.代码片段:public class JavaContest public static void fun (short n) System.out.print(short );public static void fun (Short n) System.out.print(SHORT );public static void fun (Long n) System.out.print(LONG );public static void main(String args) Short y = 0;int z = y;fun(y);fun(z);请问编译运行的结果是什么?A

15、 short LongB SHOTR LONGC 编译出错D 运行时抛出异常15.代码片段:contestKiller = new ReallyBigObject();/这里省略部分代码contestKiller = null;/*在这里补充代码*/以下哪一选项的代码是告诉虚拟机尽最大的能力去回收 contestKiller 这个对象所占用的内存?A. Runtime.getRuntime().freeMemory()B. Runtime.gc()C. System.freeMemory()D. Runtime.getRuntime().growHeap()E. System.gc()二多项选择(5*5=25)16. 给出一个尚未使用泛型的方法:11. public static int getSum(List list) 12. int sun = 0;13. for(Iterator iter = (list).iterator();iter.hashNext();)14. int i = (Integer) iter.next().intValue;15. sum += i;16. 17. return sum;18.为了使用泛型,需要对代码做以下哪三项改动?A. 删除第 14 行B. 将第 14 行替换成

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

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