Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why THIS output?

 
Yohan Shikari
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class AQuestion
{
public void method(Object o)
{
System.out.println("Object version");
}

public void method(String s)
{
System.out.println("String Version");
}

public static void main (String args[])
{
AQuestion question = new AQuestion();
question.method(null);
}

}

In the above code: the output is "String Version"
Why is it so?

Why NOT "Object version"

Pls explain
 
Raghu Shree
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
String is more specific then Object. So it calls String arguments version.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic