This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes System.out.print problem 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 "System.out.print problem" Watch "System.out.print problem" New topic
Author

System.out.print problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

KB book 543

when an object reference is passed to System.out.print,it
gives the class name (at least that's meaningful)
followed by the @ symbol, followed by the unsigned hexadecimal representation of
the object's hashcode.


but when an object of type string or Integer or List or Set or any of the collections is passed,it gives the content of that type



how this possible ?

OCPJP 6.0 93%
OCPJWCD 5.0 98%
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
System.out.print() calls toString() on the object you pass it. Each of the classes that you mention overrides toString() to provide output that is more user friendly.
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

list ,sets, maps too override toString() ?
are there any more classes which override toString() ?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3825

mohitkumar gupta wrote:list ,sets, maps too override toString() ?
are there any more classes which override toString() ?

Most API classes do override where it makes sense.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
IMO most of the final classes overrides toString() method.

One of the final class which does not overrides toString() i know is java.util.Arrays class

SCJP 6.0 96%

(Connecting the Dots ....)
 
 
subject: System.out.print problem