What is “this” keyword in java?
- Within an instance method or a constructor, this is a reference to the current object — the object whose method or constructor is being called. Y
- can refer to any member of the current object from within an instance method or a constructor by using this.
Usage of this keyword
- Used to refer current class instance variable.
- To invoke current class constructor.
- It can be passed as an argument in the method call.
- It can be passed as argument in the constructor call.
- Used to return the current class instance.
- Used to invoke current class method (implicitly)