OO Programming with Java


Primitives datatypes

The current object is represented by the this keywords. An access to an attribute or the called of an operation is then expressed by this.attribute or this.operation() ; thus, an expression such as attribute=value; is translated into this.attribute=value;

  1. Improvement: this keyword
public class Person {
  private Date birthdate;
  public Person(Date birthdate)            { this.setBirthDate(birthdate); }
  public void setBirthDate(Date birthdate) { this.birthdate = birthdate;   }
  public Date getBirthDate()               { return this.birthdate;        }
}
  1. As an exercicse, how to extend Persons with the following characteristics ?

16 - 17