Page 930 - AP Computer Science A, 7th edition
P. 930
22. (E) It is wise to have an equals method that is compatible with t he compareTo m et hod, nam ely , n1.equals(n2) and n1.compareTo(n2)==0 have the same value if n1 and n2 are Name objects. However, nothing in the Java language mandates that if a class has a compareTo method, it must also have an equals method. Choice A is true. You know this because the Name class has no mutator methods. Thus, Name objects can never be changed. Choice B is true: If a Name is initialized with null references, each of the methods w ill t hrow a NullPointerException. C hoic e C is t rue: If n1.equals(n2) is true, then n1.compareTo(n2) == 0 is true, because both are conditions for equality of n1 and n2 and should therefore be consistent. Choice D is true: If the parameter is null, the compareTo method will throw a NullPointerException.