G2A Many GEOs


a guest Mar 31st, 2020 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Course c1 = new Course(false, 123, “CMP”, 4)
  2. Course c2 = new Course(false, 175, “MAT”, 3)
  3. c1.compareTo(c2);
  4. //would return -1 because c1.courseNum < c2.courseNum
  5. c2.compareTo(c1); // would return 1
  7. "An employee is a person"
  9. The Person class has the method  compareTo(Person p)
  10. In all classes that inherit from the Person class, for example: Employee, Faculty, Student, and any other… their compareTo methods will also have the same signature … compareTo(Person p)
  11. Why? Because these are all types of Person objects via inheritance rules
  12. EXTENDS :-)
  14. You don’t need to, and you should NOT implement the Comparable Interface in the child classes
  15. public class Person implements Comparable<Person> {……
  16. that’s the only place the interface should be implemented… not in any of the child classes… but the method should be overridden whenever specified
  17. Here is the caveat…. Is every Person that could potentially be passed into the compareTo(Person p) of a child class … Employee for example.. an Employee? an instanceof the class we’re in???
  18. Answer: No
  19. So how do we address this issue???
  20. Do you remember how to check if instanceof Employee?
  22. Jansen - quick question about the employee class. For its equal method, is it always going to be false because every employee has different employee #?
  23. Teacher - YES even the employeeID should match for 2 Employee Objects to assure they are the same
  25. Justin - what do you return if the person isn’t an instanceof employee? super.compareTo?
  26. Teacher - YES! BINGO!
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand