when we don't override eqauls() and hashCode() methods,Object.equlas() gives false and hashcode() may be true or false value returning. But i don't get the part why do we need to override those two method what is the wrong happening here?
please guide me on those. [ April 14, 2007: Message edited by: Shiva Mohan ]
But i don't get the part why do we need to override those two method what is the wrong happening here?
Well, you don't have to override those two methods.
The default equals() method (from Object class) will return the value of true, if two references are referring to the same instance. The default hashCode() method will use the identity hash as the hashcode. This hashcode will very likely be different for different instances, but may not be as there can only be so many different values for hashcode.
If this behavior is fine for your purposes, then there is no need to override those two methods.
Originally posted by Shiva Mohan: if the behavior is not fine for purposes, (Actually i have no idea when we really need to override those two methods regarding hashtable)
Hate to point out the obvious but it's instances of your class, designed for your program. It's your decision whether two instances of your class are equal or not. There is no simple answer as it is a design issue -- you have to decide how instances of your class should be treated, and whether the default methods is what you want.