第八十六題: |
Given: abstract class A { A x = new B(); |
What are four valid examples of polymorphic method calls? (Choose four.) A. x.a2(); B. z.a2(); C. z.c1(); D. z.a1(); E. y.c1(); F. x.a1(); |
答案:ABDF |
題目範圍:多形 |
解析: C錯在z被轉型為A類別,雖然z是C的本質不會改變,但是這種情況下呼叫A沒有的方法是不可以的 E選項雖然程式上是正確的,但是題目問的是跟多型有關的選項,直接呼叫y.c1();是跟多型無關的 |
第八十七題: |
A team of programmers is involved in reviewing a proposed design for a new utility class, After some discussion, they realize that the current design allows other classes to access methods in the utility class that should be accessible only to methods within the utility class itself. What design issue has the team discovered? A. Tight coupling B. Low cohesion C. High cohesion D. Loose coupling E. Weak encapsulation F. Strong encapsulation |
答案:E |
題目範圍:物件封裝 |
解析: 這有點在考英文閱讀阿~ 一個程式設計團隊要設計一個utility class,他們討論結果要讓外部類別可以直接存取這個utility class內部的元素,而那些元素本應該只被utility class本身存取 這樣他們做了什麼樣的決定? 答案是:弱的封裝 封裝指的是類別內部的元素設定為private,提供getter與setter方法來從外部存取或修改 |
第八十八題: |
Which Three statements are true? (Choose Three.) A. A final method in class X can be abstract if and only if X is abstract. B. A protected method in class X can be overridden by any subclass of X. C. A private static method can be called only within other static methods in class X. D. A non-static public final method in class X can be overridden in any subclass of X. E. A public static method in class X can be called by a subclass of X without explicitly referencing the class X. F. A method with the same signature as a private final method in class X can be implemented in a subclass of X. G. A protected method in class X can be overridden by a subclass of X only if the subclass is in the same package as X. |
答案:BEF |
題目範圍:基本觀念 |
解析: A:abstract類別的abstract方法不可以是final B:覆寫沒有protected或private等等的限制,any subclass of X當然也是可以 C:static方法可以被一般方法呼叫;static方法中只能呼叫static方法 D:final的方法不可被覆寫 E:static方法可以直接被呼叫,不需要先實作物件 F:(待補) G:覆寫沒有protected或private等等的限制 |
第八十九題: |
Given: public class Car { public class MeGo extends Car { |
What two must the programmer do to correct the compilation errors? (Choose two.) A. insert a call to this() in the Car constructor B. insert a call to this() in the MeGo constructor C. insert a call to super() in the MeGo constructor D. insert a call to super(vin) in the MeGo constructor E. change the wheelCount variable in Car to protected F. change line 3 in the MeGo class to super.wheelCount = 3; |
答案:DE |
題目範圍:建構子 |
解析: 如果父代的建構子都是有參數的,那子代的建構子中,就必須明確的寫出super()這一行來傳遞參數 |
第九十題: |
Given: interface DeclareStuff { |
What is the result? A. s 14 B. s 16 C. s 10 D. Compilation fails. E. An exception is thrown at runtime. |
答案:D |
題目範圍:介面(interface) |
解析: 介面中的方法,只能是public的可見度,即使不特別加上public也會預設為public 因此繼承了DeclareStuff的doStuff方法必須為public,否則編譯時就會報錯 |