how does the call to overriden methods take place in case of dynamic dispatch
<pre><code>class a extends b {
    void h() {
        System.out.println("class a");
    }
    public static void main(String[]args) {
        b x = new a();
        c y = new b();
        c z = new a();

        x.h();      //output class a
        y.h();      //output class b
        z.h();      //output class a
    }
}

class b extends c {
    void h() {
        System.out.println("class b");
    }
}
class c {
    void h() {
        System.out.println("class c");
    }
}
</code></pre>

<p>Whats is the precedence in which it checks which method to call. I am confused as to how the JVM decides which method to call when I use dynamic dispatch. The output in this case is</p>

<pre><code>class a
class b
class a
</code></pre>

<p>and when I remove the overridden method from class a the output is</p>

<pre><code>class b
class b
class b
</code></pre>
