2009年2月11日 星期三

第79題

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.
答案:C
參考:6-5 繼承、7-3 存取修飾詞的使用

------------------------------------------------------------
5. System.out.println(new XMLMessage().getText());
>>3. String getText(){return "<msg>text</msg> ";} //<msg>text</msg>

沒有留言:

張貼留言