title: Dynamic method dispatching in Java
body: <p>The following is the code snipplet regarding my doubt.</p>
  
  <pre><code>class A {
      void someMethod(A param) {
          System.out.println("A");
      }
  }
  
  class C extends A {
      void someMethod(C param) {
          System.out.println("C");
      }
  }
  
  class DMD {
      public static void main(String[] args) {
          A ac = new C();
          C c = new C();
          ac.someMethod(c);
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre class="lang-none prettyprint-override"><code>A
  </code></pre>
  
  <p>but I excepted the output as</p>
  
  <pre class="lang-none prettyprint-override"><code>C
  </code></pre>
  
  <p>Because I have allocated memory for <code>C</code>, and <code>A</code> is referring to <code>C</code>'s memory location, so if I call the method on the <code>A</code> reference which is pointing to <code>C</code>, and the argument is passed as <code>C</code> type, then I expect the <code>someMethod(C)</code> method should execute.</p>
  
  <p>Can anyone please give me the proper reason for this behaviour?</p>
  
  <p>Thanks in advance.</p>