File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 3775

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 ....)
 
wood burning stoves
 
subject: System.out.print problem
 
Similar Threads
outputing an arraylist of arraylists to a file.
Doubt in Generic collection
Collection.toArray() method
mixing generic & nongeneric
Using Lists and converting them to arrays problem