*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why THIS output? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why THIS output?" Watch "Why THIS output?" New topic
Author

Why THIS output?

Yohan Shikari
Greenhorn

Joined: Apr 01, 2005
Posts: 13
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

Joined: Mar 18, 2005
Posts: 143
hi,
String is more specific then Object. So it calls String arguments version.


Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="http://groups.yahoo.com/group/scjp_share" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="http://groups.yahoo.com/group/JavaBeat_SCWCD" target="_blank" rel="nofollow">SCWCD Group</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why THIS output?