Author
Need clarification on overloaded method?
Thennam Pandian
Ranch Hand
Joined: Oct 11, 2005
Posts: 163
posted Aug 18, 2010 05:14:33
0
if i call the above method using "test(null)", it is calling the method which takes String as a argument.
Can anybody explain me, how it is called?
Martin Vanyavchich
Ranch Hand
Joined: Sep 16, 2008
Posts: 241
Java calls the method with the 'narrowest' type that you pass as an argument. String is more specific than Object.
this prints
short
short
long
long
SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
posted Aug 18, 2010 06:23:44
0
This should go into the FAQ if it hasn't already, as it seems to come up quite often.
Muhammad Khojaye
Ranch Hand
Joined: Apr 12, 2009
Posts: 341
David Newton wrote: This should go into the FAQ if it hasn't already, as it seems to come up quite often.
Its already. http://faq.javaranch.com/java/ScjpFaq#mostSpecific
http://muhammadkhojaye.blogspot.com/
subject: Need clarification on overloaded method?