this Keyword in Java


Use this to refer to the current object instance within its class.

Source Code

public class Car {
    int modelYear;
    String modelName;
    public Car(int year, String name) {
        this.modelYear = year; // 'this' refers to the current object instance
        this.modelName = name;
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments