aspose file tools
The moose likes Beginning Java and the fly likes overloading method output need explanation 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 » Beginning Java
Reply Bookmark "overloading method output need explanation" Watch "overloading method output need explanation" New topic
Author

overloading method output need explanation

Athira Vineeth
Greenhorn

Joined: Sep 06, 2010
Posts: 16
Hi

in the below example


The output of this program is "String".
Why so?Why it is not executing the printValue(Object ob) method?
Panagiotis Kalogeropoulos
Rancher

Joined: May 27, 2011
Posts: 99

Although both methods are applicable to your situation (both can accept null as a parameter), the most specific method will be called, or in other words, the method that is "closer" to the argument that you specify. Since a parameter in printValue(String ob) can be passed to printValue(Object ob) also, but not vice versa, then the printValue(String ob) is more specific and that is why it is called. The same rule applies to primitives too. For instance, check the following code:



The most specific method is called depending on the arguments.

Hope this helps!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32651
    
    4
It’s in the Java Language Specification (JLS); look for the links to ยง15.12, too. Note this is a complicated subject, even by the standards of the JLS.
Athira Vineeth
Greenhorn

Joined: Sep 06, 2010
Posts: 16

yes its help me a lot.

thank you so much for your time.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: overloading method output need explanation
 
Similar Threads
Ranch roundup game question
can i change the return type in method overloading?
What is the output for the below code is different?
int Literal to short Conversion
Static methods