It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

Ok looking at the answers below all I gotta say is don't rely on them. The objects hashCode method may or may not return the memory address. It's JVM implementation dependent. And even if it does most object will override this method. So any code relying on these methods to get the memory addresses will break more often than it will work. Anyway when you are working with Java you shouldn't be thinking of this.
– ThiharaMay 7 '13 at 10:58

4 Answers
4

If you have not overridden the toString() method in your object's class, it will invokes the default implementation defined in the Object class, which says:

The toString method for class Object returns a string consisting of the name of
the class of which the object is an instance, the at-sign character `@', and the
unsigned hexadecimal representation of the hash code of the object.

So, you will get the hashCode() representation of the Object , which may or may not be its address as it is implementation dependent. This is what Javadoc says about hashCode():

As much as is reasonably practical, the hashCode method defined by class Object
does return distinct integers for distinct objects. (This is typically
implemented by converting the internal address of the object into an integer,
but this implementation technique is not required by the JavaTM programming
language).

toString() implementation is called. If you have overriden this, then your implementation will be called otherwise by default Object toString() implemtation will be called which prints hashCode of that object

If you look at String Class, it overrided the toString method , thats why when do