Answers The code does not compile. The code compiles cleanly and shows "Object Version". The code compiles cleanly and shows "String Version" <<CORRECT ANS>> The code throws an Exception at Runtime. Can anyone Plz explain How Compiler deduced that. Plz also mention the thumbrule for the same
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
Both methods method(Object o) and method(String s) can take a null as parameter, but compiler decides whih of them most optimal. method(Object o) is most general but method(String s) most concrete and compiler chooses second method with String parameter.
Serghei is quite correct here. But the word "specific" is a better choice than "optimal" or "concrete". That is, the compiler chose String because it is more specific than Object (from which String is derived).
Hi Barry. Thanks for correction. Unfortunately English is not my mother tongue and not my second language.
Joined: Apr 02, 2004
Answers The code does not compile. The code compiles cleanly and shows "StringBuffer Version". The code compiles cleanly and shows "String Version" What would be result now since now both strinbuffer and sting are both specific.
Joined: Jul 24, 2002
Compile-time error because reference to method is ambiguous.