SCJP 1.6版考題 045

出自 陳富國維基館
於 2013年3月30日 (六) 07:40 由 Ikk (對話 | 貢獻) 所做的修訂 (新頁面: Gadget has-a Sprocket and Gadget has-a Spring and Gadget is-a Widget and Widget has-a Sprocket Which two code fragments represent these relationships? (Choose two) A. class W...)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
前往: 導覽搜尋
Gadget has-a Sprocket and
Gadget has-a Spring and
Gadget is-a Widget and
Widget has-a Sprocket

Which two code fragments represent these relationships? (Choose two)
  A. class Widget{Sprocket s;}
     class Gadget extends Widget{Spring s;}
  B. class Widget{}
     class Gadget extends Widget{Spring s1; Sprocket s2;}
  C. class Widget{Sprocket s1; Spring s2;}
     class Gadget extends Widget{}
  D. class Gadget{Spring s;}
     class Widget extends Gadget{Sprocket s;}
  E. class Gadget{}
     class Widget extends Gadget{Sprocket s1; Spring s2;}
  F. class Gadget{Spring s1; Sprocket s2;}
     class Widget extends Gadget{}

解答


Ans: A C

解說: is-a繼承 , has-a 擁有