«^»
3.2. Using getClass in the code of equals

Since the equals method appears in a class called Date, you would think that the target of equals must be an object of class Date, and so this kind of call of getClass always returns a value describing the class Date. However, suppose we derive a class called NamedDate from Date:

public class NamedDate extends Date
{
   private String iName:
   ...
}

Suppose that NamedDate does not override equals. If we write:

tFirstNamedDate.equals(tSecondNamedDate)
then this will be a call of Date's equals method and both calls of getClass will return values describing the class NamedDate. So, even though this code appears in the class declaration for Date, in some circumstances the first call of getClass will return a value describing a subclass of the class Date.