【正文】
22. } 23. } What is the result? A. 2 B. 3 C. 1 2 。amp。 19. (2 )。amp。 15. boolean b2 = false。 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。 15. } else (() == 0) { 16. (zero)。 QUESTION 45 Given: 11. public static void main(String[] args) { 12. String str = null。 9. } 10. (o)。 7. if(x==5) break z。 x 7。 QUESTION 44 Given: 1. public class Breaker2 { 2. static String o = 。 ,可以使用斷言檢查從不會(huì)發(fā)生的情況 ,也就是斷言表達(dá)式應(yīng)該使程序保持在進(jìn)入它之前的狀態(tài)。 } 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ī)則: 。 15. default: assert false。 QUESTION 43 Given: 11. public void go(int x) { 12. assert (x 0)。 } 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è)父類沒(méi)有的異常,錯(cuò)誤。 18. } 19. public static void main(String[] args) { 20. try { new B().process()。 16. (B,)。 } Answer: DF StackOverflowError 出現(xiàn)在遞歸遞死了的時(shí)候 ~~ QUESTION 42 Given: 11. class A { 12. public void process() { (A,)。 x++) doStuff(x)。 } E. for(int x = 0。 } void doTwo(int y) { doThree(y)。 y++) doStuff(y)。 } C. for(int y = 10。 static { x[1] = 8。 y++) (x[y])。 for(int y = 0。 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 考察重寫(xiě),子類中的重寫(xiě)方法的作用域不可以 reduce(減?。?。 6. public int height。 2. public class Hypotenuse { 3. public InnerTriangle it = new InnerTriangle()。} What is the result? A. foofoofoofoofoo B. foobarfoobarbar C. foobarfoofoofoo D. foobarfoobarfoo E. barbarbarbarbar F. foofoofoobarbar G. foofoofoobarfoo Answer: D 域不具有多態(tài)性!對(duì)域來(lái)說(shuō),對(duì)象是什么類型就是什么。 10. (((Base)s).FOO)。 8. ()。 6. ()。 3. public static void main(String[] args) { 4. Base b = new Base()。 }調(diào)用父類的構(gòu)造函數(shù)。所以可以改成 public Sub() { this(5)。 } Answer: CD 問(wèn)題出在 public Sub() { = 5。 } D. Change line 13 to: public Sub() { super(5)。 B. Change line 2 to: protected int a。 } 13. public Sub() { = 5。 3. protected Super(int a) { = a。 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。 31. Cat cat = (Cat)animal。 } 14. } 15. class Cat extends Animal { 16. public String noise() { return meow。 QUESTION 36 Given: 11. class Animal { public String noise() { return peep。 調(diào)用的是 Bar 類中的。 ()。 } 38. } Invoked with: Foo f = new Bar()。 37. public void addFive() { += 5。 (f )。 } Answer: D QUESTION 35 Given: 31. class Foo { 32. public int a = 3。 } E. class Man { private DogbestFriend。 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。即 High/Strong/Tight cohesion, Low/Weak/Loose coupling。s API, and replaces the old algorithm with the new algorithm, being careful that her changes adhere strictly to the class39。s chief scientist has just improved the performance of one of the utility classes39。 } 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ì)象。 } F. class Gadget { Spring s1。 } E. class Gadget { } class Widget extends Gadget{ Sprocket s1。 } class Gadget extends Widget { } D. class Gadget { Spring s。 } C. class Widget { Sprocket s1。 } B. class Widget { } class Gadget extends Widget { Spring s1。 } 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。 } 2. interface B { public void bMethod()。 What is the result? A. r, t, t, B. r, e, o, C. Com