【正文】
d at line 1 of to pile and run Demo to print pizzapizza? A. import utils.*。 Which code fragment, inserted at line 23, allows the code to pile? A. df = new DateFormat()。 F. String regex = \\w[ \.] +。 16. } 17. } What is the result when the programmer attempts to pile the code and run it with the mand java Converter 12? A. It is true that j==i. B. It is false that j==i. C. An exception is thrown at runtime. D. Compilation fails because of an error in line 13. Answer: D args 是一個 String 類型的數(shù)組,第 13 行應(yīng)該是 int i = (args[0])。 17. try { 18. ()。 String 類有一個 concat 函數(shù), String str = (one)。 s1 = (abc) 。 (abc) 。 4. int [][]y = x。 } 11. public class Sprite { 12. public int fubar( Foo foo ) { return ()。 a[1]=200。 B. static final int[] a。 } 16. public static void main(String[] args) { 17. Alpha a = new Beta()。} 12. public Point getPoint() { return new Point()。 14. new Rock(granite )。 14. (a)。 : 5. import .*。所以說,刪除一個鍵對應(yīng)的 Person 對象并不會刪除所有的條目,他們的 key 都不同嘛。 } 5. public int getLosses() { return losses。//[13, 14, 16] 14. (treeSet)。 7. TreeSetInteger subSet = new TreeSetInteger()。 21. (s + + subs)。 : 12. import .*。. C. Replace line 13 with for (int i : intList) {. D. Replace line 13 with for (Iterator iter : intList) {. E. Replace the method declaration with sum(Listint intList). F. Replace the method declaration with sum(ListInteger intList). Answer: A,C,F 考察把原始類型轉(zhuǎn)換成泛型。QUESTION 1 a pregenerics implementation of a method: 11. public static int sum(List list) { 12. int sum = 0。則把 List 轉(zhuǎn)換成 ListInteger,由于類型參數(shù)不能為基本類型,所以 E 不正確,而第 13 行中 Iterator 轉(zhuǎn)換成 IteratorInteger, Integer 可以自動裝箱和拆箱,所以第 14 行不需要。 13. public class Explorer2 { 14. public static void main(String[] args) { 15. TreeSetInteger s = new TreeSetInteger()。 22. } 23. } What is the result?A. Compilation fails. B. An exception is thrown at runtime. C. [608, 610, 612, 629] [608, 610] D. [608, 610, 612, 629] [608, 610, 629] E. [606, 608, 610, 612, 629] [608, 610] F. [606, 608, 610, 612, 629] [608, 610, 629] Answer: E 考察 TreeSet 以及它的 subSet 方法,兩個 true 表示包括 608 和 611。 8. for(int i = 10。//[10, 11, 12, 13, 14, 16, 17, 18, 19, 20] 15. (15)。 } 6. public String toString() { 7. return + wins + , + losses + 。 C 選項: 向 HashSet 中插入另外一個 Person 對象將會引起第二個對象覆蓋第一個對象 。 6. public class SortOf { 7. public static void main(String[] args) { 8. ArrayListInteger a = new ArrayListInteger()。 15. } 16. } What is the result? A. [1, 2, 3, 5] B. [2, 1, 3, 5] C. [2, 5, 3, 1] D. [5, 3, 2, 1] E. [1, 3, 5, 2] F. Compilation fails. G. An exception is thrown at runtime. Answer: C (a)。 15. } 16. public static void main(String[] a) { new Mountain()。 } 13. } 14. class Triangle { 15. public Triangle() { 16. // insert code here 17. } 18. } Which code, inserted at line 16, correctly retrieves a local instance of a Point object?A. Point p = () 。 18. Beta b = (Beta)a。 static { a=new int[2]。 } Answer: A,B 考察 static 修飾符。 } 13. public void testFoo() { 14. fubar( 15. // insert code here 16. )。 5. (y[2][1])。 B. (abc)。 F. (abc)。用來把字符串添加到 s 的尾部,并把結(jié)果返回給 str,注意 String 類型的變量是不變的, s并沒有變化。 19. } catch (IOException e) { 。 : 11. String test = Test A. Test B. Test C.。 Answer: E 正則表達式, String regex = \\.\\s*。 B. df = ()。 B. static import utils.*。//導入 Repetition 類中的 twice 靜態(tài)方法。 } 4. class Horse implements Animal { 5. Long weight = 1200L。 i2 = null。 2 . public class SomeApp { 3. public static void main(String[] args) { 4. byte[] bytes = new byte[256] 。 : 11. public class ItemTest { 12. private final int id。 16. Pass p = new Pass()。 6. doSomethingElse(o)。第七行結(jié)束時,局部變量 o 引用變成了 B,而此時全局變量 o 還在引用 A。 What is the result? A. r, t, t, B. r, e, o, C. Compilation fails. D. An exception is thrown at runtime. Answer: C if (check = ())這個錯誤,編譯器會給出錯誤警告,不能將 int 轉(zhuǎn)換為 boolean 之類的。 } C. class Widget { Sprocket s1。 } class Widget extends Gadget{ } Answer: AC hasa 關(guān)系:包含關(guān)系 isa 關(guān)系:繼承關(guān)系 usea 關(guān)系:關(guān)聯(lián)關(guān)系 Gadget hasa Sprocket and Gadget hasa spring 指的是 Gadget 類中包含 Sprocket 和Spring 對象; Gadget isa Widget 指的是 Gadget 繼承自 Widget; Widget hasa Sprocket 指的是 Widget 類包含 Sprocket 對象。 QUESTION 34 Which Man class properly represents the relationship Man has a best friend who is a Dog? A. class Man extends Dog { } B. class Man implements Dog { } C. class Man { private BestFriend dog。 37. public void addFive() { += 5。 QUESTION 36 Given: 11. class Animal { public String noise() { return peep。 3. protected Super(int a) { = a。 } Answer: CD 問題出在 public Sub() { = 5。 6. ()。 2. public class Hypotenuse { 3. public InnerTriangle it = new InnerTriangle()。 y++) (x[y])。 } void doTwo(int y) { doThree(y)。 16. (B,)。 15. default: assert false。 x 7。 15. } else (() == 0) { 16. (zero)。 19. (2 )。amp。 19. } 20. } What is the result? A. null B. zero C. some D. Compilation fails. E. An exception is thrown at runtime. Answer: D 第十五行應(yīng)該是 else if QUESTION 46 Given: 11. public class Test { 12. public static void main(String [] args) { 13. int x = 5。 7. if(x==5) break z。 } Which statement is true? A. All of the assert statements are used appropriately. B. Only the assert statement on line 12 is used appropriately. C. Only the assert statement on line 15 is used appropriately. D. Only the assert statement on line 18 is used appropriately. E. Only the assert statements on lines 12 and 15 are used appropriately. F. Only the assert statements on lines 12 and 18 are used appropriately. G. Only the assert statements on lines 15 and 18 are used appropriately. Answer: D 使用斷言的規(guī)則: 。 18. } 19. public static void main(String[] args) { 20. try { new B().process()。 } E. for(int x