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; 
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.