File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

print(this)???

 
chao-long liao
Ranch Hand
Posts: 78
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 133
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 78
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for help.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic