9. Consider the following illustration. What problem exists with the packaging? You may wish to reference Appendix G on the Unified Modeling Language (UML) for assistance.
A.You can have only one class per package.
B.Packages cannot have associations between them.
C.Package com.ocajexam.backing_beans fails to meet the appropriate packaging naming conventions.
D.Package COM.OCAJEXAM.UTILS fails to meet the appropriate packaging naming conventions.
11. When instantiating an object with generics, should angle brackets, box brackets, parentheses, or double-quotes be used to enclose the generic type? Select the appropriate answer.
A.List <Integer> a = new ArrayList <Integer> ();
B.List [Integer] a = new ArrayList [Integer] ();
C.List {Integer} a = new ArrayList {Integer} ();
D.List "Integer" a = new ArrayList "Integer" ();
A B C D
A
泛型使用尖括号。B、C和D不正确。泛型不能放入方括号、大括号和双引号中。
12. When organizing the elements in a class, which order is preferred?
22. Which of the following statements will not compile?
A.if(true);
B.if(true) {}
C.if(true) {;}
D.if(true) {;;}
E.if(true); {};
F.All statements will compile.
A B C D E F
F
所有的语句都会编译。
23. Given: public class Dinner { public static void main (String[] args) { boolean isKeeperFish = false; if (isKeeperFish = true) { System.out.println("Fish for dinner"); } else { System.out.println("Take out for dinner"); } } } What will be the result of the application's execution?
24. You need to update a value of a hash table (that is, HashMap) where the primary key must equal a specified string. Which statements would you need to use in the implementation of this algorithm?
A.Iteration statement
B.Expression statement
C.Conditional statement
D.Transfer of control statement
A B C D
ABC
迭代、表达式和条件语句可以用来实现该算法。下面的代码段演示了通过编程使用这些语句来替换一个人左手小指上的戒指。这些语句的前面具有标识它们类型的注释。 import java.util.HashMap; public class HashMapExample { public static void main(String[] args) { HashMap <String, String> leftHand = new HashMap <String, String> (); leftHand.put("Thumb", null); leftHand.put("Index finger", "Puzzle Ring"); leftHand.put("Middle finger", null); leftHand.put("Ring finger", "Engagement Ring"); leftHand.put("Little finger", "Pinky Ring"); // 迭代语句 for(String s : leftHand.keySet()) { // 条件语句 if(s.equals("Little finger")) { System.out.println(s + "had a" + leftHand.get(s)); // 表达式语句 leftHand.put("Little finger", "Engineer's Ring"); System.out.println(s + "has an" + leftHand.get(s)); } } } } $ Little finger had a Pinky Ring $ Little finger has an Engineer's Ring D不正确。在这个算法中没有控制转换语句。
25. The for loop has been enhanced in Java 5.0. Which is not a common term for the improved for loop?