hi celina
i remember this dicussion took place when i was active in
SCJP forum. i'll try to find and give the link to u...
it had finally...almost clear explanation...
but here what i remember as flow of resolution,
1. first the declared class is checked for the method
2. if the first class "fails" then the parent methods that were derived in child are traversed
3.also the following thing we need to keep in mind,
"there is a implicit casting occuring by java compiler" and the "fial"
word in 2nd rule will mean that the compiler couldn't find ANY method, **even after applying implicit cast**, that matches the call.
4. if there is a "direct(/perfect)" match in the declaring class of the object IT IS APPLIED w/o any other consideration.
these points solves ur puzzle i guess because, say u 've following code,
now here as 'c' has been 'declared' as Child object when we call c.get(2) is goes an searches the method space for Child class (meaning only those methods which are Child's declared methods) (Rule-1 applied)
now as of combination of Rule-2&3 it tries to see if it can cast 2 to float. IT CAN cast. the compiler records this as say event-1.
compiler also sees that there is method get() from Parent which can be applied here. so say that is noted down as event-2.
so.....now THE COMPILER is confused (amongst event-1 and event-2 results) because it has two options when the code will run-
1) to use Child's get() or
2) to use Parent's get() that was derived
BUT if u reverse the order(Child having argument int and Parent having float) than also we will get two events but as of Rule-4 it determines to call Child's method and it doesn't give us compilation error.
u can try it.
hope this helps.
regards
maulin
PS: btw, i gave the explanation here so...i may not try to find that link i was talking about but i guess that is okay...u can search in SCJP forum for my name (may be u'll find it)...