2009年2月9日 星期一

第66題

5. class Thingy{ Meter m = new Meter(); }
6. class Component {void go() { System.out.print("c");}}
7. class Meter extends Component {void go() { System.out.print("m"); }}
8.
9. class DeluxeThingy extends Thingy {
10. public static void main(String[] args) {
11. DeluxeThingy dt = new DeluxeThingy();
12. dt.m.go();
13. Thingy t = new DeluxeThingy();
14. t.m.go();
15. }
16. }
Which two are true? (Choose two.)
A. The output is mm.
B. The output is mc.
C. Component is-a Meter.
D. Component has-a Meter.
E. DeluxeThingy is-a Component.
F. DeluxeThingy has-a Component.
答案:AF
參考:6-5 繼承、7-9 多型
-------------------------------------------------------------------------
9. class DeluxeThingy extends Thingy { //DeluxeThingy 是Thingy 的子類別
7. class Meter extends Component {void go() { System.out.print("m"); }} //Meter 是Component 的子類別
12. dt.m.go(); //print m
14. t.m.go(); //print m

9. class DeluxeThingy extends Thingy { 繼承Thingy
5. class Thingy{ Meter m = new Meter(); } Thingy 的屬性有Meter ,有Meter表示有
7. class Meter extends Component {void go() { System.out.print("m"); }} 有Meter表示有component

沒有留言:

張貼留言