SCJP(OCPJP) 考古題解析 第27題

Given:

class One {
    void foo() {}
}
class Two extends One {
    // insert method here
}

Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.)


A. int foo(){/* more code here */}
B. void foo(){/* more code here */}
C. public void foo(){/* more code here */}
D. private void foo(){/* more code here */}
E. protected void foo(){/* more code here */}

答案:BCE


解析:


Overriding rule

回傳值型態必須要一樣 所以A錯

子類別覆載的方法存取屬性必須比父類別覆載的方法存取屬性一樣或更開放,D錯


0 意見:

張貼留言