- Hands-On Design Patterns with Java
- Dr. Edward Lavieri
- 64字
- 2021-06-24 14:57:59
The this reference
In Java, we can use the this keyword as a reference to the current object. For example, the following code snippet sets the color of the current Bicycle object:
public void setColor(String theColor) {
this.color = theColor;
}
The preceding setColor method accepts a String parameter and assigns it to the color instance variable of the current object.