title: Method overloading with Parent and Child class as parameter
body: <p>I have 3 classes <code>GrandParent</code>, <code>Parent</code> and <code>Child</code>, where 
  <code>Child extends Parent</code> and <code>Parent extends GrandParent</code></p>
  
  <pre><code>public class Main {
      void test(GrandParent gp){System.out.println("GrandParent");}
      void test(Parent p){System.out.println("Parent");}
  
      public static void main(String args[]){
          GrandParent obj = new Child();
          Main mainObj = new Main();
          mainObj.test(obj);  // This calls test(GrandParent gp)
  
          mainObj.test(new Child()); // This calss test(Parent gp)
      }
  }
  </code></pre>
  
  <p>In above code in the 2 calls to <code>test()</code> method both with <code>Child</code> object calls different methods. In one it's doing compile-time and in other run-time binding. This sounds little weird to me. How would you explain this?</p>