Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overloading the methods with Object and String

 
thomas davis
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Follow up here. Please stop posting duplicates of the same question in different places; it's more work for us to sort through them.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic