title: why compilation fails for that example
body: <p>I was working on SCJP6 dumps when I found this confusing exercise:</p>
  
  <p>Given classes defined in two different files:</p>
  
  <pre><code>package packageA;
  
  public class Message {
  
  String getText() { return “text”; }
  
  }
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>package packageB;
  
  public class XMLMessage extends packageA.Message {
  
  String getText() { return “&lt;msg&gt;text&lt;/msg&gt;”;}
  
  public static void main(String[] args) {
  
  System.out.println(new XMLMessage().getText());
  
  }
  
  }
  </code></pre>
  
  <p>What is the result of executing XMLMessage.main?</p>
  
  <pre><code>A. text
  
  B. Compilation fails.
  
  C. &lt;msg&gt;text&lt;/msg&gt;
  
  D. An exception is thrown at runtime.
  </code></pre>
  
  <p>The answer was: B, but I don't understand why; I think the answer should be C.</p>