Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Rani Singh   on Nov 06 In Java Category.

  
Question Answered By: Danny Perkins   on Nov 06

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. In other
words, this method returns a string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())

The above is the direct copy and paste from the java  API.

If you create an object of someother class, the overloaded hashcode method is
called. Create an Object of class Object. (ex Object ob = new Object();) now
call hashcode on this and just print  it. one will be printed in decimal and
other will be in hex. to change decimal to hex use
Integer.toHexString(ob.hashCode()). see the value and mail me back.

But in fact, the hashCode method in Object class returns the memory location  of
the object.

Share: