This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes toString() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "toString()" Watch "toString()" New topic
Author

toString()

Surya Bavirti
Greenhorn

Joined: Sep 08, 2008
Posts: 13
what is the need for overriding toString()?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

What does the Object class toString() method API tell you ?


[My Blog]
All roads lead to JavaRanch
ruban raj
Greenhorn

Joined: Aug 05, 2008
Posts: 7
The toString method is widely implemented. It provides a simple, convenient mechanism for debugging classes during development. It is also widely used for logging, and for passing informative error messages to Exception constructors and assertions


Regards,
Vasiammal.p
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

It's also what is displayed by default in tables, lists and trees in Swing and AWT.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
vijay makam
Ranch Hand

Joined: Sep 06, 2008
Posts: 31
As you yourself have rightly used the word "need" if you want to print a descriptive information about your object then you will override toString method.


Regards,
vijay
Surya Bavirti
Greenhorn

Joined: Sep 08, 2008
Posts: 13
Thanks to All My Friends
 
GeeCON Prague 2014
 
subject: toString()