1. class One{
2. public One foo(){return this;}
3. }
4. class Two extends One{
5. public One foo(){return this;}
6. }
7. class Three extends Two{
8. //insert method here
9. }
Which two methods, inserted individually, correctly complete the Three class? (Choose two.)
A. public void foo(){}
B. public int foo(){return 3;}
C. public Two foo(){return this;}
D. public One foo(){return this;}
E. public Object foo(){return this;}
-----------------------------------------------------------------------------------
答案:CD
參考:6-5 繼承
繼承及改寫的觀念
A. public void foo(){} //試圖改寫第5行但回傳是錯的
B. public int foo(){return 3;} //試圖改寫第5行但回傳是錯的
C. public Two foo(){return this;}
D. public One foo(){return this;}
E. public Object foo(){return this;} //試圖改寫第5行但回傳是錯的
沒有留言:
張貼留言