File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why THIS output?" Watch "Why THIS output?" New topic

Why THIS output?

Yohan Shikari

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();


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
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="" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="" target="_blank" rel="nofollow">SCWCD Group</a>
I agree. Here's the link:
subject: Why THIS output?
It's not a secret anymore!