Reference type variable "this"
It indicates instance itself.
can use in instance method and constructor! (CANNOT use in static method(class method))
To distinguish local variable and instance variable
class Car {
//instance variable
String color;
String gearType;
int door;
Car(String color, String gearType, int door) {
//instance variable this.____
//this.color <=> Car.color
this.color = color;
this.gearType = gearType;
this.door = door;
}
}
example :
Last updated
Was this helpful?