Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes overriding toString() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "overriding toString()" Watch "overriding toString()" New topic
Author

overriding toString()

Surya Bavirti
Greenhorn

Joined: Sep 08, 2008
Posts: 13
why programmeres overriding toString() method? where it is really usefull in projects?.i have seen this a lot of times in java examples.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2896
    
    1

"toString" in one shot gives you a short description about an object !! It may print an important state of your object, which comes handy in displaying an object .

If your printing some objects , you can show some user understandable message by overriding 'toString()' method, rather than printing its hashcode values !


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: overriding toString()
 
Similar Threads
how to load the values in one object?
Overloading and Overriding
toString()
why new date() prints date ?????
Object of class having toString() method