Back to notes -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    A Person class that can return its private date of birth.Lecture 4 - slide 29 : 29
Program 2
public class Person{

  private string name;
  private Date dateOfBirth, dateOfDeath;  

  public Person (string name, Date dateOfBirth){
    this.name = name;
    this.dateOfBirth = dateOfBirth;
    this.dateOfDeath = null;
  }

  public Date GetDateOfBirth(){
     return dateOfBirth;                  
  }                                       

  public ushort AgeAsOf(Date d){
    return (ushort)(d.GetYear() - dateOfBirth.GetYear());
  }

  public bool Alive(){
    return dateOfDeath == null;
  }

  public override string ToString(){
    return "Person: " + name + " " + dateOfBirth;
  }

  // Other getter and setter methods

}
 
 
 
Two private dates.
 
 
 
 
 
 
 
 
Leaking the private birth date from 
a person object.