I have a class A with a subclass B. The class A has a method foo()
that calls C.test(this)
. In class C, there are two methods: test(A a)
and test(B b)
. Whenever A.foo()
is called, the method test(A a)
is used. That seems normal to me. However, whenever B.foo()
is called, the method test(A a)
is also used, instead of test(B b)
(which is what I want). This surprises me.
Why does this happen? How can I change my code structure such that I obtain the behaviour that I want?