File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes print(this)??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "print(this)???" Watch "print(this)???" New topic
Author

print(this)???

chao-long liao
Ranch Hand

Joined: Jul 29, 2001
Posts: 78
public class Test {
public static void main (String args []) {
new Test();
}
public Test () {
System.out.println(this);
}
}
output: Test@affc70
why no error?
What's the meaning about printing the class itself?
thanks for help
Paul Villangca
Ranch Hand

Joined: Jun 04, 2002
Posts: 133
The Object class has a toString() method, which is inherited by all its subclasses (which means all classes), unless overriden.
What you see printed out is the default toString() method, which shows the class name and its hashcode. Kinda useless, though, so you might wanna override the toString() method in your class.
chao-long liao
Ranch Hand

Joined: Jul 29, 2001
Posts: 78
Thanks for help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: print(this)???