method overriding using Interface
<pre><code>    interface I
    {
       void show();
    } 

    class A implements I
    {
    void show()
    {
       System.out.println("class A");
     }
    public static void main(String s[])
    {
      I i=new A();
      i.show();
      i.toString();
    }
  }
</code></pre>

<p>Q> As interface I does not contain the abstract method toString() but still The following code gets compiled. How?</p>

<p>when super class variable is used to refer sub class obj then compiler first searches the similar method in the super class if not found gives error.
here Interface does not contain the method toString().</p>

<p>ex=></p>

<pre><code>class A
{
  void show()
  {
   System.out.println("show");
  }
}

class B
{
  void show()
  {
   System.out.println("show B");
  }

  void display()
  {
   System.out.println("display B");
  }

  public static void main(String s[])
  {
    A a=new B();
    a.show();           //will execute
    a.display();        //give error 
}
</code></pre>
