posted 18 years ago
Let's walkthru the code to make things clear how method resolution works
in this overload scenario.
On Line 1, at compile time, compiler looks at line 1, and interprets that
you are trying to call eating method of class A (as 'a' is reference type A) by passing an argument of class type B.
But class A has eating method which accepts arguments of class A. But from the inheritance structure, B extends A, that means wherever you can pass of type A, a type B class can be passed. So, for line 1, compiler chooses to use eating method from class A and that is the method invoked even at runtime (which version of overload method to be called, is decided at compile time, unlike override methods).
Hope this is clear, if not more confusing, what you already know.