use of "this" keyword
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sunil_Kumar
Posted On:   Friday, September 27, 2002 12:12 AM

i have a method which uses "this" keyword can anyone explain what is its utility in this method given below:

public void setMood(int mood) {
int old = this.mood;
this.mood = mood;
repaint();
changes.firePropertyChange("mood",
new Integer(old), new Integer(mood));
}

thanks in advance

Re: use of "this" keyword

Posted By:   Thomas_Hackel  
Posted On:   Friday, September 27, 2002 12:37 AM

the keyword this indicates access to a member of the CURRENT class.

public void setMood(int mood) {
// remember the old MOOD value inside the CLASS
int old = this.mood;
// set MOOD member (inside the class) to the new
// value given with the method setMood
this.mood = mood;
repaint();
// here it uses the MOOD variable from the method
// not from the class
changes.firePropertyChange("mood", new Integer(old), new Integer(mood));
}
About | Sitemap | Contact