title: How does a call to overridden method is resolved in method overriding?
body: <p>According to my understanding, if call to a method is made which is overridden then the method is decided on the basis of the object at the runtime.</p>
  
  <p>for eg.</p>
  
  <pre><code>class A
  {
    void fun1()
      {
        System.out.println("fun1 of clss A");
      }
  }
  class B extends A
  {
    void fun1()
    {
       System.out.println("fun1 of class B");
     }
  }
  </code></pre>
  
  <p>Now,</p>
  
  <pre><code>A a=new B();
  a.fun1();
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>fun1 of class B
  </code></pre>
  
  <p><strong>But</strong>,</p>
  
  <p>I am not able to understand the output of following program</p>
  
  <pre><code>class A
  {
    void fun1()
      {
        System.out.println("fun1 of clss A");
      }
  }
  class B extends A
  {
    void fun1()
    {
       System.out.println("fun1 of class B");
       fun2();
     }
    private void fun2()
   {
      System.out.println("fun2 of class B");
   }
  }
  class C extends B
  {
      private void fun2()
   {
      System.out.println("fun2 of class C");
   }
  }
  </code></pre>
  
  <p>Now,</p>
  
  <pre><code>A a =new C();
  a.fun1();
  </code></pre>
  
  <p>It is giving output:</p>
  
  <pre><code>fun1 of class B
  fun2 of class B
  </code></pre>
  
  <p>(It means not the inherited fun1 but the fun1 is class B is getting executed)</p>
  
  <p>Why ? fun1 is overriden but it is not in class C and object of C is created at runtime? Why fun1 of B is getting executed?</p>