How to call the correct overloaded method? : <p>I have a class <strong>A</strong> with a subclass <strong>B</strong>. The class <strong>A</strong> has a method <code>foo()</code> that calls <code>C.test(this)</code>. In class <strong>C</strong>, there are two methods: <code>test(A a)</code> and <code>test(B b)</code>. Whenever <code>A.foo()</code> is called, the method <code>test(A a)</code> is used. That seems normal to me. However, whenever <code>B.foo()</code> is called, the method <code>test(A a)</code> is also used, instead of <code>test(B b)</code> (which is what I want). This surprises me.</p>

<p>Why does this happen? How can I change my code structure such that I obtain the behaviour that I want?</p>
