Chris Bremer wrote:In my Cattle Drive OOP-3 method LastNameCompare, I implement Comparator yet I don't override the equals(object obj) method. I am referencing a java book that says when you implement an interface, all methods associated with it must be overriden...can anyone clarify this for me?
If it truly says "all methods
associated with it must be overriddent," then it's a poorly written book indeed.
The rule is that a concrete class cannot have any abstract methods. All the methods defined in an interface are implicitly abstract, so any class that implements the interface must provide implementations for those method--or else itself be delcared an abstract class.
HOWEVER, your class already provides an equals() implementation. Every single class does, by virtue of the fact that the inherit it from Object. So if you don't provide your own equals() method, you'll just use Object's; two distinct Comparator objects will never be equal in that case, Comparator explicitly names equals() even though it's not necessary in order to provide documentation about what equality is intended to mean for Comparators. It even says right there in the docs, "it is always safe not to override Object.equals(Object)."
And do note that the equals() method is for equality of Comparator objects, not of the objects they're comparing.