SUN公司SCJP题库.doc

上传人:11****ws 文档编号:2994041 上传时间:2019-05-16 格式:DOC 页数:21 大小:604.50KB
下载 相关 举报
SUN公司SCJP题库.doc_第1页
第1页 / 共21页
SUN公司SCJP题库.doc_第2页
第2页 / 共21页
SUN公司SCJP题库.doc_第3页
第3页 / 共21页
SUN公司SCJP题库.doc_第4页
第4页 / 共21页
SUN公司SCJP题库.doc_第5页
第5页 / 共21页
点击查看更多>>
资源描述

1、1yModule 1-JAVA 基础一、选择题:Question 1Given:35. String #name = “Jane Doe“;36. int $age=24;37. Double _height = 123.5;38. double temp = 37.5;Which two are true? (Choose two.)A. Line 35 will not compile.B. Line 36 will not compile.C. Line 37 will not compile.D. Line 38 will not compile.Answer: AD 标识符以 字母,

2、下划线,或者 $开始Question 2Given:11. public class Test 12. public static void main(String args) 13. int x =5;14. boolean b1 = true;15. boolean b2 = false;16.17.if(x=4) 19. System.out.print(“2 “);20. if (b2 = true) 22. 23. What is the result?A. 2B. 3C. 1 2D. 2 3E. 1 2 3F. Compilation fails.G. An exceptional

3、 is thrown at runtime.Answer: D 注意 20 行,=为赋值,不要被骗Question 3Given:42. public class ClassA 43. public int getValue() 44. int value=0;45. boolean setting = true;46. String title=“Hello“;47. if (value | (setting 48. if (value = 1 49. 50. And:70. ClassA a = new ClassA();271. a.getValue();What is the resu

4、lt?A. 1B. 2C. Compilation fails.D. The code runs with no output.E. An exception is thrown at runtime.Answer: C 编译不通过,47 行 value 为 int 类型不是 booleanQuestion 4Given:11. public void testIfA() 12. if(testIfB(“True“) 13. System.out.println(“True“);14. else 15. System.out.println(“Not true“);16. 17. 18. pu

5、blic Boolean testIfB(String str) 19. return Boolean.valueOf(str);20. What is the result when method testIfA is invoked?A. TrueB. Not trueC. An exception is thrown at runtime.D. Compilation fails because of an error at line 12.E. Compilation fails because of an error at line 19.Answer: A 19 行,如果 str

6、为 true 则返回 ture,否则返回 falseQuestion 5Given:11. public static void main(String args) 12. Integer i = new Integer(1) + new Integer(2);13. switch(i) 14. case 3: System.out.println(“three“); break;15. default: System.out.println(“other“); break;16. 17. What is the result?A. threeB. otherC. An exception i

7、s thrown at runtime.D. Compilation fails because of an error on line 12.E. Compilation fails because of an error on line 13.F. Compilation fails because of an error on line 15.Answer: A 就是两个 Integer 类型相加Question 6Given:11. public static void main(String args) 12. String str = “null“;13. if (str = nu

8、ll) 14. System.out.println(“null“);15. else (str.length() = 0) 316. System.out.println(“zero“);17. else 18. System.out.println(“some“);19. 20. What is the result?A. nullB. zeroC. someD. Compilation fails.E. An exception is thrown at runtime.Answer: D 这题真恶心 15 行少个 ifQuestion 7Given:10.int x=0;11.int

9、y=10;12. do l3. y-;14. +x;15. while (x 10,所以直接跳出循环,输出 x=12Question 9Given:35. int x= 10;36. do 37. x-;38. while(x6) break;14. 15. System.out.println(i);16. What is the result?A. 6B. 7C. 10D. 11E. Compilation fails.F. An exception is thrown at runtime.Answer: E 15 行 i 超出了作用域Question 11Given:55. int x

10、= 1, 2,3,4, 5;56. int y =x;57. System.out.println(y2);Which is true?A. Line 57 will print the value 2.B. Line 57 will print the value 3.C. Compilation will fail because of an error in line 55.D. Compilation will fail because of an error in line 56.Answer: B 没争议,考察数组下标是从 0 开始Question 12Which two code

11、 fragments(片段) correctly(正确) create and initialize a static array of int elements? (Choose two.)A. static final int a = 100,200 ;B. static final int a;static a=new int2; a0=100; a1=200; C. static final int a = new int2 100,200 ;D. static final int a;static void init() a = new int3; a0=100; a1=200; A

12、nswer: AB c 不能指定长度,d 不能在 init 方法中赋值,要么在 static 代码块中Question 13Given:11. public static void main(String args) 12. Object obj = new int 1,2,3 ;13. int someArray = (int)obj;14. for (int i: someArray) System.out.print(i +“ “)15. What is the result?A. 1 2 3B. Compilation fails because of an error in line

13、 12.C. Compilation fails because of an error in line 13.5D. Compilation fails because of an error in line 14.E. A ClassCastException is thrown at runtime.Answer: A 没争议,foeach 循环遍历数组Question 14Given:11. String elements = “for“, “tea“, “too“ ;12. String first = (elements.length 0)? elements0 : null;Wh

14、at is the result?A. Compilation fails.B. An exception is thrown at runtime.C. The variable first is set to null.D. The variable first is set to elements0.Answer: DQuestion 15Given:10. public class Bar 11.static void foo(int.x) 12. / insert code here13. 14. Which two code fragments, inserted independ

15、ently(独立的) at line 12, will allow the class to compile? (Choose two.)A. foreach(x) System.out.println(z);B. for(int z : x) System.out.println(z);C. while( x.hasNext() System.out.println( x.next();D. for( int i=0; i x.length; i+ ) System.out.println(xi);Answer: BD x 相当于一个数组 ,a 明显错没有 foreach,c 中 x 没有

16、hadNext 方法Question 16A programmer(程序员) needs to create a logging method that can accept(接受) an arbitrary(随意任意) number of arguments. For example, it may be called in theseways:logIt(“log message 1 “);logIt(“log message2”,”log message3“);logIt(“log message4“, “log message5“, “log message6“);Which decl

17、aration(说明) satisfies(符合) this requirement(需求)?A. public void logIt(String * msgs)B. public void logIt(String msgs)C. public void logIt(String. msgs)D. public void logIt(String msg1, String msg2, String msg3)Answer: C 可变长参数Question 171. public class A 2. public String doit(int x, int y) 3. return “a

18、“;4. 5.6. public String doit(int. vals) 7. return “b“;68. 9. Given:25. A a=new A();26. System.out.println(a.doit(4, 5);What is the result?A. Line 26 prints “a“ to System.out.B. Line 26 prints “b“ to System.out.C. An exception is thrown at line 26 at runtime.D. Compilation of class A will fail due to

19、 an error in line 6.Answer: A 确定参数和可变长参数同时存在的时候,优先考虑确定参数的Question 18Given a file GrizzlyBear.java:1. package animals.mammals;2.3. public class GrizzlyBear extends Bear 4. void hunt() 5. Salmon s = findSalmon();6. s.consume();7. 8. and another file, Salmon.java:1. package animals.fish;2.3. public cla

20、ss Salmon extends Fish 4. void consume() /* do stuff */ 5. Assume(假定 ) both classes are defined in the correct directories for theft packages, and that the Mammal class correctly defines the findSalmon() method. Which two changes allow this code to compile correctly? (Choose two.)A. add public to th

21、e start of line 4 in Salmon.javaB. add public to the start of line 4 in GrizzlyBear.javaC. add import animals.mammals.*; at line 2 in Salmon.javaD. add import animals.fish.*; at line 2 in GrizzlyBear.javaE. add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.javaF. add import animals.mammals.

22、GrizzlyBear.*;at line 2 in Salmon.javaAnswer: AD 调用不同包下的类,要先导入,方法权限要设置成 publicQuestion 19Given:10. package com.sun.scjp;11. public class Geodetics 12. public static final double DIAMETER = 12756.32; / kilometers13. Which two correctly access(访问) the DIAMETER member of the Geodetics class? (Choose tw

23、o.)A. import com.sun.scjp.Geodetics;public class TerraCarta public double halfway() return Geodetics.DIAMETER/2.0; B. import static com.sun.scjp.Geodetics;7public class TerraCarta public double halfway() return DIAMETER/2.0; C. import static com.sun.scjp.Geodetics. *;public class TerraCarta public d

24、ouble halfway() return DIAMETER/2.0; D. package com.sun.scjp;public class TerraCarta public double halfway() return DIAMETER/2.0; Answer: AC b 中不能静态导入类,c 中静态导入类属性,正确,d 访问错误很明显Question 20Given classes defined in two different files:1. package util;2. public class BitUtils 3. private static void proce

25、ss(byte b) 4. 1. package app;2. public class SomeApp 3. public static void main(String args) 4. byte bytes = new byte256;5. / insert code here6. 7. What is required(必需的) at line 5 in class SomeApp to use the process methodof BitUtils?A. process(bytes);B. BitUtils.process(bytes);C. app.BitUtils.proce

26、ss(bytes);D. util.BitUtils.process(bytes);E. import util.BitUtils. *; process(bytes);F. SomeApp cannot use the process method in BitUtils.Answer: F 私有的,不能被访问Question 21Given a class Repetition(重复):1. package utils;2.3. public class Repetition 4. public static String twice(String s) return s + s; 5.

27、and given another class Demo:1. / insert code here2.3. public class Demo 4. public static void main(String args) 5. System.out.println(twice(“pizza“);6. 7. Which code should be inserted at line 1 of Demo.java to compile and run Demo to print “pizzapizza”?A. import utils.*;B. static import utils.*;8C

28、. import utils.Repetition.*;D. static import utils.Repetition. *;E. import utils.Repetition.twice();F. import static utils.Repetition.twice;G. static import utils.Repetition.twice;Answer: F 静态导入Question 22Given:1. package test;2.3. class Target(目标) 4. public String name = “hello“;5. What can directl

29、y(直接的) access and change the value of the variable(变量) name?A. any classB. only the Target classC. any class in the test packageD. any class that extends TargetAnswer: C default 类型的类本包访问权限Question 23Given:11. rbo = new ReallyBigObject();12. / more code here13. rbo = null;14. /* insert code here */Wh

30、ich statement(语句) should be placed at line 14 to suggest(促成) that the virtual machine(虚拟机) expend(消耗) effort(努力) toward recycling(回收) the memory used by the object rbo?A. System.gc();B. Runtime.gc();C. System.freeMemory();D. Runtime.getRuntime().growHeap();E. Runtime.getRuntime().freeMemory();Answer

31、: A 题很简单。英语单词很烦Question 24Given:11. class Snoochy 12. Boochy booch;13. public Snoochy() booch = new Boochy(this); 14. 15.16. class Boochy 17. Snoochy snooch;18. public Boochy(Snoochy s) snooch = s; 19. And the statements:21. public static void main(String args) 22. Snoochy snoog = new Snoochy();23.

32、snoog = null;924. / more code here25. Which statement is true about the objects referenced(引用) by snoog,snooch, and booch immediately(即刻) after line 23 executes?A. None of these objects are eligible for garbage collection(垃圾收集).B. Only the object referenced by booch is eligible for garbagecollection

33、.C. Only the object referenced by snoog is eligible for garbagecollection.D. Only the object referenced by snooch is eligible for garbagecollection.E. The objects referenced by snooch and booch are eligible(符合) for garbage collection.Answer: E snoogxsnooch 和 booch,所以 s 和 b 应该被回收掉Question 25Given:1.

34、public class GC 2. private Object o;3. private void doSomethingElse(Object obj) o = obj; 4. public void doSomething() 5. Object o = new Object();6. doSomethingElse(o);7. o = new Object();8. doSomethingElse(null);9.o=null;10. 11. When the doSomething method is called, after which line does the Object

35、 created in line 5 become available for garbage collection?A. Line 5B. Line 6C. Line 7D. Line 8E. Line 9F. Line 10Answer: D 第二个 new 不会 new 新对象,而还是以前的,只是第 8 行的时候,o 才无效!Question 26Given:11. public void genNumbers() 12. ArrayList numbers = new ArrayList();13. for (int i=0; i10; i+) 14. int value = i *

36、(int) Math.random();15. Integer intObj = new Integer(value);16. numbers.add(intObj);17. 18. System.out.println(numbers);19. Which line of code marks(标志) the earliest point that an object referenced by intObj becomes a candidate(替补) for garbage collection?10A. Line 16B. Line 17C. Line 18D. Line 19E.

37、The object is NOT a candidate for garbage collection.Answer: D 方法结束后变量失效,表示可以被回收了Question 27Which two are true? (Choose two.)A. A finalizer may NOT be invoked explicitly(直接).B. The finalize method declared in class Object takes no action.C. super.finalize() is called implicitly(隐含) by any overriding

38、 finalize method.D. The finalize method for a given object will be called no more than once by the garbage collector.E. The order in which finalize will be called on two objects is based on the order in which the two objects became finalizable.Answer: BD 稀里糊涂Question 28Given:15. public class Yippee

39、16. public static void main(String args) 17. for(int x = 1; x args.length; x+) 18. System.out.print(argsx +“ “);19. 20. 21. and two separate command line invocations(两个独立的命令行执行):java Yippeejava Yippee 1234What is the result?A. No output is produced(生产).123B. No output is produced.234C. No output is

40、produced.1234D. An exception is thrown at runtime.Copyright Tarena Corporation,2009.All rights reserved123E. An exception is thrown at runtime.234F. An exception is thrown at rijntime.1234Answer: B 第一个没有参数不输出,第二个从数组下标为 1 的地方输出Question 29Given a correctly compiled class whose source code is:1. package com.sun.sjcp;2. public class Commander 3. public static void main(String args) 4. / more code here

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

当前位置:首页 > 实用文档资料库 > 策划方案

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。