aspose file tools*
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
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: 1056

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: 19762
    
  20

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
 
jQuery in Action, 2nd edition
 
subject: Wrapper class doubt