Page 928 - AP Computer Science A, 7th edition
P. 928

21. (A) The first statement of segment I compares last names. If these are different, the method returns the int value lastComp, which is negative if lastName precedes n.lastName, positive otherwise. If last names are the same, the method returns the int result of comparing first names. Segments II and III use incorrect algorithms for comparing names. Segment II would be correct if the else part were
return lastName.compareTo(n.lastName);
Segment III would be correct if the two return statements were interchanged.
































































































   926   927   928   929   930