+91 81900 98289

this means the object whose method is running. Use it to pass the current object to another method, and to tell a field from a parameter of the same name.

A static method has no current object, so this is not allowed there. If the method needs an object, pass one in or remove static and call it on an instance.

Example

labeled returns the same Room that main created, so code is still B2.

public class Room { String code; Room(String code) { this.code = code; } Room labeled() { return this; } public static void main(String[] args) { Room room = new Room("B2"); System.out.println(room.labeled().code); } }
Returning this lets calls chain: room.labeled().code. Use chaining when each call returns the same object and the line stays readable.