甲骨文java考试答案_2015年“甲骨文杯”全国java程序设计大赛—赛前模拟题.doc...

41528d3028836879cd698677c3999917.gif2015年“甲骨文杯”全国java程序设计大赛—赛前模拟题.doc

2015年“甲骨文杯”全国Java程序设计大赛—赛前模拟题 一、单项选择。 1.代码片段: public lass 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.short Long B.SHORT LONG C.编译出错 D.运行时抛出异常 答案:C 分析:类型 JavaContest 中的方法 fun(short)对于参 数(int)不适用 2. 如下代码: public static void main(String[] args) {1(1, 2);System.out.print(“ java“); } public static void 1(int x1, int x2) {System.out.print(“hello“); } public static void 1(int x1, int x2, int x3) {System.out.print(“hi“); } 请问编译运行的结果是什么? A.hello java B.编译失败 C.hi java D.hellohi java E.hi hello java 答案:A 分析:1方法有两个变量 ,当没有给变量赋值 时打印出hello,给变量赋值时打印java。 3. 有如下变量声明: Map> map;请问以下哪个赋值语句会出错? A.map = new HashMap(); C.map = new HashMap>(); D.map = new LinkedHashMap>(); 4. 如下代码: 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、b、c和d没有被初始化 B.编译错误,因为变量a无法被访问 C.编译成功并输出0 - 0 - 0 - 0 D.编译成功并输出1 - -1 - 1 - -1 5. 给出如下代码片段: String[] elements = { “for“, “tea“, “too“ }; String first = (elements.length > 0 ) ? elements[0] : null; 以下哪个是正确的结果? A. 编译失败 B.运行时抛出异常 C.first的值被设为null D.first的值被设为“for“ 6. 代码片段: package certkiller; class Target {public String name = “hello“; } 哪些类能够直接访问并且改变name这个变量的值。 A.任意类B.只有Target这个类 C.certkiller包下的类 D.Target的子类 7. 代码片段: public class Certkiller3 implements Runnable {public 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.代码正常执行并且输出: running D.代码正常执行并且输出: runningrunning E.代码正常执行并且输出: runningrunningrunning 8. 代码片段:import java.util.*; public class TestSet {enum Num {ONE, THREE, TWO}public 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(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里的相 同。 9. 代码片段:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值