title: Class type of reference and the actual class type, which decides which method to call?
body: <p>The title may be misleading but as a non-native i couldn't figure out a better one.</p>
  
  <p>Say i have two classes, <code>Dog</code> and <code>Fox</code> :</p>
  
  <pre><code>public class Dog {
      public String bark() {
          return "Wuff";
      }
      public String play(Dog d) {
          return "Wuff" + d.bark();
      }
  }
  
  
  public class Fox extends Dog {
      public String bark() {
          return "Ringding" ;
      }
      public String play(Fox f) {
          return "Ringding" + f.bark();
      }
  }
  </code></pre>
  
  <p>And i create some instances as well call some methods</p>
  
  <pre><code>Fox foxi = new Fox();
  Dog hybrid = new Fox();
  System.out.println(hybrid.play(foxi)); // Output number 1
  System.out.println(foxi.play(hybrid)); // Output number 2
  </code></pre>
  
  <p>For the 1. Ouput I expected <code>"RingdingRingding"</code> because <code>hybrid</code> actually is a reference to an instance of the <code>Dog</code>, even if the reference has a type of <code>Dog</code>
  it still refers to an <code>Fox</code> object, but still i got this output :</p>
  
  <blockquote>
    <p>WuffRingding</p>
  </blockquote>
  
  <p>The second one i got the same problem, since <code>foxi</code> is an instance of <code>Fox</code> and <code>hybrid</code> is actually an instance of <code>Fox</code> (no matter what reference, right ?), the ouput should be <code>"RingdingRingding"</code> but then again, i got : </p>
  
  <blockquote>
    <p>WuffRingding</p>
  </blockquote>
  
  <p>Can someone explain why ? </p>