<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/**
 * A PhD is a person with a graduation year.
 */
class PhD extends Person {
  private int graduationYear; // not in the future

  /**
   * Create a PhD with given first and last names and graduation year.
   * Precondition: names are not null and don't contain ' ', and
   * gradYear is not in the future.
   */
  public PhD(String firstName, String lastName, int gradYear) {
    // Calling super() invokes the constructor for the superclass.
    // Like this(), the call to super() must be the first statement.
    // If you do not have a super() call, Java will try to insert one
    // for you, and it will fail if there is no zero-argument
    // constructor in the superclass.
    super(firstName, lastName);

    graduationYear= gradYear;
  }

  public String getName() {
    return super.getName() + ", PhD (" + graduationYear + ")";
    // Just calling `getName()`, not `super.getName()`, would cause a
    // recursive call to this same method.
  }

  /**
   * Get a short name for the person, including a title.
   */
  public String getAbbrevName() {
    // Because we don't have a method called getLastName in PhD, this
    // refers to the method in Person without needing a `super.` prefix.
    return "Dr. " + getLastName();
  }
}
</pre></body></html>