SCJP 1.6版考題 027
出自 陳富國維基館
10. class One{ 11. void foo(){} 12. } 13. class Two extends One{ 14. //insert method here 15. } 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 */}
解答
Ans: B C E
解說:
Overriding rule 回傳值型態必須要一樣 所以A錯 子類別覆載的方洲存取屬性必須比父類別覆載的方法存取屬性一樣或更開放,D錯
|