【正文】
ew Object()。第七行結(jié)束時(shí),局部變量 o 引用變成了 B,而此時(shí)全局變量 o 還在引用 A。 15. } else { 16. ((0) + , )。 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 = ())這個(gè)錯(cuò)誤,編譯器會(huì)給出錯(cuò)誤警告,不能將 int 轉(zhuǎn)換為 boolean 之類的。 } 4. class D implements B { 5. public void bMethod(){} 6. } 7. class E extends D implements C { 8. public void aMethod(){} 9. public void bMethod(){} 10. public void cMethod(){} 11. } What is the result? A. Compilation fails because of an error in line 3. B. Compilation fails because of an error in line 7. C. Compilation fails because of an error in line 9. D. If you define D e = new E(), then () invokes the version of bMethod() defined in Line 5. E. If you define D e = (D)(new E()), then () invokes the version of bMethod() defined in Line 5. F. If you define D e = (D)(new E()), then () invokes the version of bMethod() defined in Line 9. Answer: F 考察多態(tài)性, new E()產(chǎn)生一個(gè) E 類型的對(duì)象,是 D 的子類, D e = new E()和 D e = (D)(new E())完全一樣, e 引用 E 類型的對(duì)象,那么 ()引用的就是第 9 行的 bMethod() QUESTION 32 Given that: Gadget hasa Sprocket and Gadget hasa Spring and Gadget isa Widget and Widget hasa Sprocket Which two code fragments represent these relationships? (Choose two.) A. class Widget { Sprocket s。 } C. class Widget { Sprocket s1。 } E. class Gadget { } class Widget extends Gadget{ 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 對(duì)象; Gadget isa Widget 指的是 Gadget 繼承自 Widget; Widget hasa Sprocket 指的是 Widget 類包含 Sprocket 對(duì)象。s API, and replaces the old algorithm with the new algorithm, being careful that her changes adhere strictly to the class39。 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。 } Answer: D QUESTION 35 Given: 31. class Foo { 32. public int a = 3。 37. public void addFive() { += 5。 ()。 QUESTION 36 Given: 11. class Animal { public String noise() { return peep。 31. Cat cat = (Cat)animal。 3. protected Super(int a) { = a。 B. Change line 2 to: protected int a。 } Answer: CD 問題出在 public Sub() { = 5。 }調(diào)用父類的構(gòu)造函數(shù)。 6. ()。 10. (((Base)s).FOO)。 2. public class Hypotenuse { 3. public InnerTriangle it = new InnerTriangle()。 QUESTION 40 Given: 2. public class Hi { 3. void m1() { } 4. protected void m2 () { } 5. } 6. class Lois extends Hi { 7. // insert code here 8. } Which four code fragments, inserted independently at line 7, will pile? (Choose four.) A. public void m1() { } B. protected void m1() { } C. private void m1() { } D. void m2() { } E. public void m2() { } F. protected void m2() { } G. private void m2() { } Answer: ABEF 考察重寫,子類中的重寫方法的作用域不可以 reduce(減?。?。 y++) (x[y])。 } C. for(int y = 10。 } void doTwo(int y) { doThree(y)。 x++) doStuff(x)。 16. (B,)。 } 22. } What is the result? A. Exception B. A,B,Exception C. Compilation fails because of an error in line 20. D. Compilation fails because of an error in line 14. E. A NullPointerException is thrown at runtime. Answer: D 第十四行拋出了一個(gè)父類沒有的異常,錯(cuò)誤。 15. default: assert false。 ,可以使用斷言檢查從不會(huì)發(fā)生的情況 ,也就是斷言表達(dá)式應(yīng)該使程序保持在進(jìn)入它之前的狀態(tài)。 x 7。 9. } 10. (o)。 15. } else (() == 0) { 16. (zero)。 15. boolean b2 = false。 19. (2 )。 22. } 23. } What is the result? A. 2 B. 3 C. 1 2 。amp。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。 QUESTION 45 Given: 11. public static void main(String[] args) { 12. String str = null。 7. if(x==5) break z。 QUESTION 44 Given: 1. public class Breaker2 { 2. static String o = 。 } 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ī)則: 。 QUESTION 43 Given: 11. public void go(int x) { 12. assert (x 0)。 18. } 19. public static void main(String[] args) { 20. try { new B().process()。 } Answer: DF StackOverflowError 出現(xiàn)在遞歸遞死了的時(shí)候 ~~ QUESTION 42 Given: 11. class A { 12. public void process() { (A,)。 } E. for(int x = 0。 y++) doStuff(y)。 static { x[1] = 8。 for(int y = 0。 6. public int height。} What is the result? A. foofoofoofoofoo B. foobarfoobarbar C. foobarfoofoofoo D. foobarfoobarfoo E. barbarbarbarbar F. foofoofoobarbar G. foofoofoobarfoo Answer: D 域不具有多態(tài)性!對(duì)域來說,對(duì)象是什么類型就是什么。 8. ()。 3. public static void main(String[] args) { 4. Base b = new Base()。所以可以改成 public Sub() { this(5)。 } D. Change line 13 to: public Sub() { super(5)。 } 13. public Sub() { = 5。 What is the result? A. peep B. bark C. meow D. Compilation fails. E. An exception is thrown at runtime. Answer: E 類型轉(zhuǎn)換錯(cuò)誤, ClassCastException。 } 14. } 15. class Cat extends Animal { 16. public String noise() { return meow。 調(diào)用的是 Bar 類中的。 } 38. } Invoked with: Foo f = new Bar()。 (f )。 } E. class Man { private DogbestFriend。即 High/Strong/Tight cohesion, Low/Weak/Loose coupling。s chief scientist has just improved the performance of one of the utility classe