aspose file tools*
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

Win a copy of Java 8 in Action this week in the Java 8 forum!
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())
Don't get me started about those stupid light bulbs.
subject: toString
Similar Threads
toString( ) method ...
.equals()-Regarding collections
toString and hashCode methods usage.
Garbage collection doubt