previous | start | next

## Overriding the `equals` Method

- Notion of equality depends on class
- Common definition: compare all fields

      public class Employee
      {
         public boolean equals(Object otherObject)
            // not complete--see below
         {
            Employee other = (Employee)otherObject;
            return name.equals(other.name)
               && salary == other.salary;
         }
         ...
      }

- Must cast the `Object` parameter to subclass
- Use `==` for primitive types, `equals` for object fields

previous | start | next