1、scjp 题目与详细解答(1) Question 1 Given: 11. public interface Status 12. /* insert code here */ int MY_VALUE = 10; 13. Which three are valid(正确的) on line 12? (Choose three.) /接口中的修饰符只能是 public,static,finalA. final B. static C. native D. public E. private F. abstract G. protected Answer: ABD Question 2 Give
2、n: 10. public class Bar 11.static void foo(int.x) 12. / insert code here 13. 14. Which two code fragments(片段), inserted independently(独立地) at line 12, will allow the class to compile? (Choose two.) A. foreach(x) System.out.println(z); foreach是个错误的关键词B. for(int z : x) System.out.println(z); C. while(
3、 x.hasNext() System.out.println( x.next(); 对于可变长参数(数组不能调用 hasNext()方法)D. for( int i=0; i F. class Man private BestFriend Answer: D Question 10 Given: 11. public class Person 12. private name; 13. public Person(String name) 14. this.name = name; 15. 16. public int hashCode() 17. return 420; 18. 19. W
4、hich is true? A. The time to find the value from HashMap with a Person key depends on the size of the map. B. Deleting(删除) a Person key from a HashMap will delete all map entries(条目) for all keys of type Person. C. Inserting a second Person object into a HashSet will cause the first Person object to
5、 be removed(覆盖) as a duplicate(复制品). D. The time to determine(决定) whether a Person object is contained(包含)in a HashSet is constant(不变的,持续的) and does NOT depend on the size of the map. Answer: A Question 11 Given: 23. Object myObjects = 24. new integer(12), 25. new String(”foo”), 26. new integer(5),
6、27. new Boolean(true) 28. ; 29. Arrays.sort(myObjects); 30. for( int i=0; imyObjects.length; i+) 31. System.out.print(myObjectsi.toString(); 32. System.out.print(” “); 33. What is the result? A. Compilation fails due(由于) to an error in line 23. B. Compilation fails due to an error in line 29. C. A C
7、lassCastException occurs in line 29. 数组中的所有元素都必须是可相互比较的,String 和 Boolean与 Integer是没有可比性的。D. A ClassCastException occurs in line 31. E. The value of all four objects prints in natural order. (自然顺序)Answer: C Question 12 12. Given: 13. public class Pass 14. public static void main(String 1 args) 15. in
8、t x= 5; 16. Pass p = new Pass(); 17. p.doStuff(x); 18. System.out.print(” main x = “+ x); 19. 20. 21. void doStuff(int x) 22. System.out.print(” doStuff x = “+ x+); 23. 24. What is the result? A. Compilation fails. B. An exception is thrown at runtime. C. doStuffx = 6 main x = 6 D. doStuffx = 5 main
9、 x = 5 E. doStuffx = 5 main x = 6 F. doStuffx = 6 main x = 5 Answer: D Question 13 Given: 10. package com.sun.scjp; 11. public class Geodetics 12. public static final double DIAMETER = 12756.32; / kilometers 13. Which two correctly access the DIAMETER member of the Geodetics class? (Choose two.) A.
10、import com.sun.scjp.Geodetics; public class TerraCarta public double halfway() return Geodetics.DIAMETER/2.0; 静态成员可以用类名直接调用B. import static com.sun.scjp.Geodetics; public class TerraCarta public double halfway() return DIAMETER/2.0; C. import static com.sun.scjp.Geodetics. *; 静态导入,调用时省略类名,.0 新特性publ
11、ic class TerraCarta public double halfway() return DIAMETER/2.0; D. package com.sun.scjp; public class TerraCarta public double halfway() return DIAMETER/2.0; Answer: AC Question 14 Given: 枚举可以声明在类外或类内,在类内定义的枚举,引用时需要通过所在类名来引用10. class Nav 11. public enum Direction NORTH, SOUTH, EAST, WEST 12. 13. pu
12、blic class Sprite 14. / insert code here 15. Which code, inserted at line 14, allows the Sprite class to compile? A. Direction d = NORTH; B. Nav.Direction d = NORTH; C. Direction d = Direction.NORTH; 此项若想通过,必须导入import Nav.*;D. Nav.Direction d = Nav.Direction.NORTH; Answer: D Question 15 Given: 10. i
13、nterface Foo int bar(); 11. public class Sprite 12. public int fubar( Foo foo) return foo.bar(); 13. public void testFoo() 14. fubar( 匿名内部类15. / insert code here 16.); 17. 18. Which code, inserted at line 15, allows the class Sprite to compile? A. Foo public int bar() return 1; B. new Foo public int
14、 bar() return 1; C. new Foo() public int bar()return 1; D. new class Foo public int bar() return 1; Answer: C Question 16 Click the Exhibit button. 10. interface Foo 11. int bar(); 12. 13. 14. public class Beta 15. 16. class A implements Foo 成员内部类17. public int bar() return 1; 18. 19. 20. public int
15、 fubar( Foo foo) return foo.bar(); 21. 22. public void testFoo() 23. 24. class A implements Foo 局部内部类,有局部类时,局部类优先25. public int bar() return 2; 26. 27. 28. System.out.println( fubar( new A(); 29. 30. 31. public static void main( String argv) 32. new Beta().testFoo(); 33. 34. Which three statements a
16、re true? (Choose three.) A. Compilation fails. B. The code compiles and the output is 2. C. If lines 16, 17 and 18 were removed, compilation would fail. D. If lines 24, 25 and 26 were removed, compilation would fail. E. If lines 16, 17 and 18 were removed, the code would compile and the output would
17、 be 2. F. If lines 24, 25 and 26 were removed, the code would compile and the output would be 1. Answer: BEF Question 17 Given: 1. package sun.scjp; 2. public enum Color RED, GREEN, BLUE 1. package sun.beta; 2. / insert code here 3. public class Beta 4. Color g = GREEN; Color 要用 import sun.scjp.Colo
18、r; 导入 ,GREEN要用 import sun.scjp.Color.*或 import static sun.scjp.Color.GREEN;导入5. public static void main( String argv) 6. System.out.println( GREEN); 7. The class Beta and the enum Color are in different packages. Which two code fragments(片段), inserted individually(个别的) at line 2 of the Beta declaration, will allow this code to compile? (Choose two.) A. import sun.scjp.Color.*; B. import static sun.scjp.Color.*; C. import sun.scjp.Color; import static sun.scjp.Color.*;