All > Technology > Programming > Java
A Java keyword that can be used to represent an instance of the class in which it appears.
this
can be used to access class variables and methods.A Java reserved word with several different uses:
- Within a constructor, it may be used as the first statement to call another constructor in the same class. For example
// Initialise with default values. public Heater() { // Use the other constructor. this(15, 20); } // Initialise with the given values. public Heater(int min,int max) { ... }
- Within a constructor or method, it may be used to distinguish between a field and a parameter or method variable of the same name. For instance:
public Heater(int min,int max) { this.min = min; this.max = max; ... }
- It can be used as a reference to the current object, typically in order to pass a reference to another object:
talker.talkToMe(this);
- Within a constructor, it may be used as the first statement to call another constructor in the same class. For example
- Browse Related Terms: Attribute, class constant, class variable, constant, encapsulation, instance variable, local variable, magic number, method variable, model-view pattern, out of scope, overloading, static field, static variable, this, variable