If you dont overridea class's equals() method,you wont be able to use those objects as a key in hashtable
equals() method in class Object uses only the == operator for comparisions.So Unless You override equals(), two Objects are considered equal only if two references refer to the same Object
can u please give a demonstration of the above explanation via code, that would be more helpful in understand the concepts more quickly
ReplyDeleteya i 2 need am example.....
ReplyDeleteSorry guys for the late replies. hashcode() can be thought of for instance ur name itself..the moment you guys were born you were given a name right...
ReplyDeleteso lets consider this case you were born as humans so equal method had to be overidden , just to prove that you are equal to human...now ones Equal method is overriden you also need to override hashcode to give u (object) some name which isnt guarnetted unique for instance Soniya can be name for multiple people.
PS: hashCode() only returns int value.So any object in a collection has a hashcode() which is not unique
gr8 example bro
ReplyDelete