The method that will be invoked is decided at compile time. The problem is that you are invoking the callMe method passing null. When you have only
callMe(Object o) and callMe(String s)
the compiler will try to find the most narrow method that can handle null. Since String is a subclass of Object, it is the narrowest type that can handle the null parameter and you are fine.
But when you add callMe(char c) the compiler no longer can decide which is the narrowest type that can handle the null parameter. This happens because both char and String are subclasses of Object and none is a subclass of the other. That is, they are not in the same inheritance tree. If they were in the same inheritance tree the compiler would be able to find the narrowest type that could handle the null parameter.
If you want the code to compile, you have to cast the null parameter to the one of the types - e.g. callMe((String)null); Now the compiler can decide what method is to be called.
Hope this helps, Stefan
SCJP 1.4, SCBCD 1.3<br />IBM 141, 484, 486
Joined: Jul 19, 2004
Hi Stefan, I think thats very much clear, Thanks for your reply.