Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing an object  RSS feed

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys, my question is,what is it that you get when you include an object refernece variable inside System.out.println. we usually get something like "ClassName@1a46e30" .what does this really mean? what is the significance of that value?
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think its the location of the object... if i'm not mistaken... i once tried to display an array without iterating through it and its what i got...or something like that..
 
Sheriff
Posts: 21289
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the source code of java.lang.Object, inside the src.zip file you can find in your JDK folder.

But since I'm such a nice guy I looked it up for you. This is the current implementation of Object.toString():
So not exactly the location (as that's not available in Java), but the hash code. By default that is something probably based on the memory location but it can of course be overridden.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!