this Keyword

this refers to the current object.


// A use of this. 
Rectangle(double w, double h) { 
    this.width = w; // this is used here
    this.height = h; 
}

Use this to reference the hidden instance variables

Member variables and method parameters may have the same name. Under this situation we can use this to reference the member variables.


Rectangle(double width, double height) { 
    this.width = width; 
    this.height = height; 
}
Home 
  Java Book 
    Class  

Class Creation:
  1. Introducing Classes
  2. A Simple Class
  3. A Closer Look at new
  4. Variables and Initialization
  5. this Keyword
  6. A Demo Class
  7. The Person class: another demo
  8. Understanding static