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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Wrapper class doubt" Watch "Wrapper class doubt" New topic
Author

Wrapper class doubt

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1050

Integer i=new Integer(100);
System.out.println(i); // why is this line printing 100 and not the reference address


http://www.lifesbizzare.blogspot.com || OCJP:81%
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

Because the Integer class has its toString() method overridden.

And you never see the reference address of objects. What you see when you print an Object instance is its hashCode. It is most likely based on the object address in memory, but it doesn't have to. It most certainly never is the reference address - that's completely hidden. Remember, references aren't pointers like in C.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrapper class doubt
 
Similar Threads
Object References & GC
== , autoboxing Doubt
are these one and the same
Is there something wrong ..
cast from string to integer