看板 java 關於我們 聯絡資訊
4. Given the following Java code: [10 points] 10. interface A { public int getValue();} 11. class B implements A { 12. public int getValue() { return 1;} 13. } 14. class C extends B { 15. // insert code here16. } What three code fragments individually at line 15, make used of polymorphism? (Choose three) (A) public void add (C c) {c.getValue();} (B) public void add (B b) {b.getValue();} (C) public void add (A a) {a.getValue();} (D) public void add (A a, B b) {a.getValue();} (E) public void add (C c1, C c2) {c1.getValue();} ANS:__ (B), (C), (D)__ 請問是否有人可以跟我解釋一下 為什麼答案是BCD嗎 我完全不了解這樣跟多形有什麼關係耶@@ 拜託了~感謝萬分 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.168.193.40
AI3767:真糟糕>< 我還以為是abe... 我得加強一下觀念了(淚) 05/04 22:59
H45:直觀啊,參數型態沒有 C 的就是 BCD 05/05 00:22
silver8250:因為只有 BCD 可以在 runtime 時期決定parameter型別 05/05 22:59
scarsnight:因為C沒有實作getValue() interface,是由其父類別實作 05/06 16:20