What is the difference between compile time linking and run time linking?
<p>I am currently reading a book and stuck at following code:</p>

<pre><code>public class TestAnimals {
    public static void main (String [] args ) {
        Animal a = new Animal();
        Animal b = new Horse();

        a.eat(); // Runs the Animal version of eat()
        b.eat(); // Runs the Horse version of eat()

    }
}

class Animal {
    public void eat() {
        System.out.println("Generic animal eating generically");
    }
}

class Horse extends Animal {
    public void eat() {
        System.out.println("Horse eating hay, oats, horse treats");
    }

    public void buck() {
    }
}
</code></pre>

<p>Please have a look at the commented lines. </p>

<p>The book goes on to say "To reiterate, the compiler looks only at the reference type, not the instance type". Really? Had this been the case, both <code>a.eat()</code> and <code>b.eat()</code> would produce same result, as they (<code>a</code> and <code>b</code>) have same reference type (which is <code>Animal</code>). </p>

<p>Also to me this seems to be the compile time binding because virtual keyword has not been used but in the book results are of run time binding. I am so confused at this point. Any help would be greatly appreciated.</p>