title: Overridding methods in anonymous class
body: <p>I am having two classes. Parent and Child.In the Child class I have used anonymous Inner class for overriding Parent class methods.If I add any methods in the Child's anonymous class(Parent Class) should I define the same method in the actual Parent class?.</p>
  
  <ol>
  <li>Can I have my own new method definition in Anonymous Class. </li>
  <li>Why the Methods in the Anonymous class should already be defined in actual Parent class</li>
  </ol>
  
  <p>Code:</p>
  
  <pre><code>public class Parent 
  {
      public static void main(String[] args) 
      {
          new Child().CallMe();
      }       
  }
  
  class Child
  {
      Parent objParent = new Parent()
      {
          void displayMsg()
          {
              System.out.println("Display Msg for Child");
          }
      };
  
      void CallMe()
      {
          objParent.displayMsg();
      }
  }
  </code></pre>
  
  <p>So in the above example if you remove <code>displayMsg()</code> either in Parent or Child its going to display error.</p>