Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A question about equals() method 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 » Programmer Certification (SCJP/OCPJP)
Bookmark "A question about equals() method" Watch "A question about equals() method" New topic
Author

A question about equals() method

avseq anthoy
Ranch Hand

Joined: Apr 27, 2004
Posts: 102
Hi!everyone.
I see Sun Certified Programmer for Java 2 Study Guide and it says that if you want objects of your class to be used as keys for a hashtable then you must override equals().But why I can put a class defined by myself into HashTable?

why the following sample has overridden equals() and hashcode() but printed "test null" rather than "test test"?



My Way,My Pace
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
The C in hashCode should be upper case. You have used lower case characters, so you really did not override the hashCode method.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question about equals() method
 
Similar Threads
Set Question : Bad equals override.
why am i getting a null value on fetching from map
what It means if you don't override equals()
overidden equals() error
hashtable working & overriding equals