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 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方法(物件是什麼型態就是那個型態的方法)