SCJP 1.6版考題 038

出自 陳富國維基館
於 2013年3月30日 (六) 07:55 由 Ikk (對話 | 貢獻) 所做的修訂 (新頁面: 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 ...)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
前往: 導覽搜尋
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;}


解答


Ans: C D

解說:

overriding  

比較要注意的是C為何可以,是因為Two is One(繼承關係)