This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Overloading methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Overloading methods" Watch "Overloading methods" New topic
Author

Overloading methods

thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
After running following code,I am getting result as given below:
Here from String!!null
Why does it call String instead of Object?When I passed null directly through the method.

Code is given below:
import java.util.*;
class OverLoadinObject
{
void aMethod1(Object obj)
{
System.out.println("Here from object!!"+obj);}

void aMethod1(String str)
{
System.out.println("Here from String!!"+str );
}
public static void main(String[] args)
{
OverLoadinObject objTestOverLoadinObject = new OverLoadinObject();

objTestOverLoadinObject.aMethod1(null);
}
}
When I passed null like following way ,the Object method gets called.
Object obj = null;
objTestOverLoadinObject.aMethod1(obj);
Here from object!!null
Here it is being called Object overloaded method,why does it behave like this? :roll:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overloading methods