"SCJP 1.6版考題 079" 修訂間的差異
出自 陳富國維基館
(新頁面: Given classes defined in two different files: 1. package packageA; 2. public class Message{ 3. String getText(){return "text";} 4. } And: 1. package packageB; 2. public class...) |
(無差異)
|
於 2013年3月30日 (六) 06:13 的最新修訂
Given classes defined in two different files: 1. package packageA; 2. public class Message{ 3. String getText(){return "text";} 4. } And: 1. package packageB; 2. public class XMLMessage extends packageA.Message{ 3. String getText(){return "<msg>text</msg>";} 4. public static void main(String[] args) { 5. System.out.println(new XMLMessage().getText()); 6. } 7. } What is the result of executing XMLMessage.main? A. text B. Compilation fails. C. <msg>text</msg> D. An exception is thrown at runtime.
解答
Ans: C
解說: 此題new XMLMessage().getText()是以XMLMessage類別中的getText方法(物件是什麼型態就是那個型態的方法)
|