This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Need clarification on overloaded method? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Need clarification on overloaded method?" Watch "Need clarification on overloaded method?" New topic
Author

Need clarification on overloaded method?

Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163


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

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/
 
I agree. Here's the link: http://jrebel.com/download
 
subject: Need clarification on overloaded method?
 
Similar Threads
Ambiguity in S&B book
Most specific method.......
Difference between Null String and Null Object
Method with null as arg
Some doubt about Method calling