jQuery in Action, 3rd edition
The moose likes Mock Exam Errata and the fly likes toString Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "toString" Watch "toString" New topic


premji danicha

Joined: Oct 15, 2001
Posts: 1
If return type of toString is String but it also return a hashcode and hashcode method return type is int. when i print the reference of any user define class object. if user define class has not toString overide method .
for example:
Myclass c=new Myclass();
System.out.println( c ); // output Myclass@hashcodenumbers
Any can inform me that how it is happend.
Nain Hwu
Ranch Hand

Joined: Sep 16, 2001
Posts: 139
Take a look at the toString() method for Object class.
It says:

this method returns a string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashcode())
I agree. Here's the link: http://aspose.com/file-tools
subject: toString
jQuery in Action, 3rd edition