On 8/9/2012 5:58 PM, bob smith wrote:
> Let's say I have a class like this:
>
> public class Kern_Pair {
> int letter1, letter2;
>
> }
>
> Can someone tell me how the default equals function will behave?
>
> like
>
> kernpair1.equals(kernpair2)
>
> ?
Teachable Moment.
The Kern_Pair class has no equals() method of its own, so it
inherits equals() from the nearest superclass that has one. Walk
up the class inheritance tree to find the nearest ancestor with an
equals(). The class inheritance tree for Kern_Pair is fairly short:
Its immediate superclass is Object (because you didn't say "extends
SomethingElse"), so the equals() method for Kern_Pair *is* the
equals() method of Object.
Now all you need to do is go to the Javadoc and study what
Object's equals() will do.
--
Eric Sosman
d