【正文】
15. public void foo() { (Bfoo )。 Answer: D 在內(nèi)部類的外圍類外使用內(nèi)部類的時(shí)候,就像上面那個(gè) p = (new Line()).getPoint() 即 p = ()。 C. Point p = (new Line()).getPoint() 。 } 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 = () 。 : 10. class Line { 11. public class Point { public int x,y。如果刪除 16, 17, 18 行,由于局部內(nèi)部類 A 在方法 testFoo()內(nèi)部屏蔽了外部的內(nèi)部類 A 可以看出不會(huì)對局部內(nèi)部產(chǎn)生任何影響。 the Exhibit button. Which three statements are true? (Choose three.) A. Compilation fails. B. The code piles and the output is 2. C. If lines 16, 17 and 18 were removed, pilation would fail. D. If lines 24, 25 and 26 were removed, pilation would fail. E. If lines 16, 17 and 18 were removed, the code would pile and the output would be 2. F. If lines 24, 25 and 26 were removed, the code would pile and the output would be 1. Answer: B,E,F 注意這里有兩個(gè)內(nèi)部類, 一個(gè)是名為 A 的內(nèi)部類 A,另一個(gè)是名為 A 的局部內(nèi)部類 A,在testFoo 方法內(nèi)部,局部內(nèi)部類將屏蔽內(nèi)部類 A。 15. } 16. public static void main(String[] a) { new Mountain()。 } 10. } 11. public class Mountain extends Rock { 12. Mountain() { 13. super(granite )。 : 5. class Atom { 6. Atom() { (atom )。 11. public interface Status { 12. /* insert code here */ int MY_VALUE = 10。 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)。 13. (a)。 11. (a)。 (5)。 6. public class SortOf { 7. public static void main(String[] args) { 8. ArrayListInteger a = new ArrayListInteger()。正確, map 越大,即 bucket 的個(gè)數(shù)越多, entry鏈的長度相應(yīng)的來說就越?。?hashcode 和桶個(gè)數(shù)取余后的數(shù)一樣的幾率就越?。ee(cuò)誤,由于 Person 對象的 hashCode 返回的值都是 420,所以 HashSet 中的 Person 對象都在一個(gè) bucket 中,組成了一條 entry 鏈表,查詢速度與 entry 鏈表的大小息息相關(guān)。綜上, HashSet 中可以添加不同的 Person 對象,只要 equals方法返回值為 false 就好。 C 選項(xiàng): 向 HashSet 中插入另外一個(gè) Person 對象將會(huì)引起第二個(gè)對象覆蓋第一個(gè)對象 。錯(cuò)誤, HashMap 中 Person 對象的鍵值不是由 Person 對象決定的,而是程序員給定的鍵,例如(123345, bob),就是把鍵為 123456的 bob對象添加到名為 staff的 HashMap中,因而 HashMap允許添加相同的對象。 15. } 16. public int hashCode() { 17. return 420。 11. public class Person { 12. private name。 } 6. public String toString() { 7. return + wins + , + losses + 。 } 4. public int getWins() { return wins。 3. public Score(int w, int l) { wins = w。//[13, 14, 15, 16] 17. (treeSet)。//[10, 11, 12, 13, 14, 16, 17, 18, 19, 20] 15. (15)。 13. (subSet)。 11. (subSet)。 i++) 9. (i)。 8. for(int i = 10。 3. 4. public class Explorer1 { 5. public static void main(String[] args) { 6. TreeSetInteger treeSet = new TreeSetInteger()。 [java] view plain copy 1. package 。 public SortedSetE subSet(E fromElement, E toElement) Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive. (If fromElement and toElement are equal, the returned set is empty.) The returned set is backed by this set, so changes in the returned set are reflected in this set, and viceversa. The returned set supports all optional set operations that this set supports. subSet 返回的是一個(gè) view,而不是 copy,所以對 subSet 的改變會(huì)反映到原 set 里面,反之,在原 set 中的變化也會(huì)反映到 subSet 里面。 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 方法,兩個(gè) true 表示包括 608 和 611。 20. (629)。 i++) 18. if(i%2 == 0) (i)。 17. for(int i = 606。 13. public class Explorer2 { 14. public static void main(String[] args) { 15. TreeSetInteger s = new TreeSetInteger()。 20. } 21. } Which two, inserted at line 11, will allow the code to pile? (Choose two. )A. public class MinMax? { The safer , easier way to help you pass any IT exams. B. public class MinMax? extends Number { C. public class MinMaxN extends Object { D. public class MinMaxN extends Number { E. public class MinMax? extends Object { F. public class MinMaxN extends Integer { Answer: D,F 必須有 N 這個(gè)泛型,所以從 CDF 中選擇,而 N 需要實(shí)現(xiàn)了 doubleValue 方法, Object 肯定不行,而 Number 和 Integer 都實(shí)現(xiàn)了這個(gè)方法。 } 15. public void add(N added) { 16. if (min == null || () ()) 17. min = added。 13. public N getMin() { return min。則把 List 轉(zhuǎn)換成 ListInteger,由于類型參數(shù)不能為基本類型,所以 E 不正確,而第 13 行中 Iterator 轉(zhuǎn)換成 IteratorInteger, Integer 可以自動(dòng)裝箱和拆箱,所以第 14 行不需要。 18. } What three changes allow the class to be used with generics and avoid an unchecked warning? (Choose three.) A. Remove line 14. B. Replace line 14 with int i = ()。 15. sum += i。 ()。QUESTION 1 a pregenerics implementation of a method: 11. public static int sum(List list) { 12. int sum = 0。 13. for ( Iterator iter = ()。 ) { 14. int i = ((Integer)()).intValue()。 16. } 17. return sum。. 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)換成泛型。 programmer has an algorithm that requires a that provides an efficient implementation of add(0, object), but does NOT need to support quick random access. What supports these requirements.? A. B. C. D. Answer: D 實(shí)現(xiàn)了 接口,并且需要高效率在首部進(jìn)行插入操作,選項(xiàng)中僅有 LinkedList符合 : 11. // insert code here 12. private N min, max。 } 14. public N getMax() { return max。 18. if (max == null || () ()) 19. max = added。 : 12. import .*。 16. TreeSetInteger subs = new TreeSetInteger()。 i 613。 19. subs = (TreeSet)(608, true, 611, true)。