public class Name
{
private String firstName;
private String lastName;
public Name(String first, String last) //constructor
{
firstName = first;
lastName = last;
}
public String toString()
{ return firstName + " " + lastName; }
public boolean equals(Object obj)
{
Name n = (Name)obj;
return n.firstName.equals(firstName) &&
n.lastName.equals(lastName);
}
public int hashCode()
{ /* implementation not shown */ }
public int compareTo(Name n)
{
/* more code */
}
}
Which statement about the
Name
class is false?
(A) Name objects are immutable.
(B) It is possible for the methods in Name to throw a NullReferenceException.
(C) If n1 and n2 are Name objects in a client class, then the expressions n1.equals(n2) and n1.compareTo(n2) == 0 must have the same value.
(D) The compareTo method throws a run-time exception if the parameter is null.
(E) Since the Name class has a compareTo method, it must provide an implementation for an equals method.