Two Laptop Bag*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Wrapper class doubt" Watch "Wrapper class doubt" New topic

Wrapper class doubt

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Integer i=new Integer(100);
System.out.println(i); // why is this line printing 100 and not the reference address || OCJP:81%
Rob Spoor

Joined: Oct 27, 2005
Posts: 19649

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.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Wrapper class doubt
Similar Threads
are these one and the same
Object References & GC
Is there something wrong ..
cast from string to integer
== , autoboxing Doubt