wood burning stoves 2.0*
The moose likes Java in General and the fly likes Overloading the methods with Object and String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Overloading the methods with Object and String" Watch "Overloading the methods with Object and String" New topic
Author

Overloading the methods with Object and String

thomas davis
Ranch Hand

Joined: Feb 01, 2003
Posts: 207
When I ran the following code by passing null as a parameter ,which method will get executed and why does not it take null as parameter?If any other object passed what could be the possible result?
After running this code snippet,I got a error as given below:
TestOverLoadinObject.java:20: cannot resolve symbol
symbol : method aMethod1 (java.lang.Object)
location: class TestOverLoadinObject
objTestOverLoadinObject.aMethod1(obj);
^

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 class TestOverLoadinObject
{

public static void main(String[] args)
{
TestOverLoadinObject objTestOverLoadinObject = new TestOverLoadinObject();
Object obj = null;
objTestOverLoadinObject.aMethod1(obj);
}
} :roll:
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Follow up here. Please stop posting duplicates of the same question in different places; it's more work for us to sort through them.


"I'm not back." - Bill Harding, Twister
 
jQuery in Action, 2nd edition
 
subject: Overloading the methods with Object and String
 
Similar Threads
why this outout
Some doubt about Method calling
null as a parameter to method
Overloading methods
deserialization and casting