wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes about Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about "toString"" Watch "about "toString"" New topic
Author

about "toString"

lang lang
Greenhorn

Joined: Nov 01, 2003
Posts: 8
I am really confused about it .
would you tell me about it and how to use it?
would you take some examples for me ?
thank you!
David Crossett
Ranch Hand

Joined: Feb 05, 2003
Posts: 102
The 'toString' method is inherited by all classes, and is originally defined in the Object class (the super parent of all objects/classes). The toString() method needs to be over-ridden (this means to replace the super-classes method definition with your own - just like when you write an applet, you over-ride the init(), start(), and paint() methods with methods to do something else you want). The original definition of toString() doesn't do too much (I'm not sure what it does at all). When you over-ride it in a program, you define how you would like YOUR data converted to 'String' data. For example, you may want to convert date/time data into a format you prefer.


One thing to know also is this: whenever you concatenate a String with any other object, an implicit call is made to the 'toString()' method. Keep this in mind if you over-ride 'toString()' and then can't figure out why you're strings look so different than you might be used to!

David
- still nothing to say


David Crossett
-nothing important to say, but learnin' plenty-
David Crossett
Ranch Hand

Joined: Feb 05, 2003
Posts: 102
Let me add that you'll get more help if you conform to the naming rules, i.e. use your name or at least one that sounds real.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: about "toString"
 
Similar Threads
TDD starting OO
Inner classes
Retrieving xm from mySQL and sending it through webservice method
How to clear screen ??
Please help about picture path.