educative.io

Educative

This keyword in getter method in java

While returning in getter we use variableName not the this.variableName why?

Hi Nitin_Kumar1,
Getter is used to returns its value which is set in the setter. “this” keyword works only when it is clear which object it is. There are no differences, adding the “this” keyword is not necessary but you can add it if It’s more clear for you. It’s just more explicit.