this

1 topic · 2 sources

Technology› Programming

Java

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); 

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.

Cite this definition

APA
MLA
Chicago