what is the difference between this.name and only name after the return statement in the getter method ie if we use return this.Name instead of return Name in the getter method then what is the difference?
This keyword usage explanation in the return atatement
hey @mishikasrvastava
The this
keyword refers to the current object in a method or constructor.
The most common use of the this
keyword is to eliminate the confusion between class attributes and parameters with the same name (because a class attribute is shadowed by a method or constructor parameter). If you omit the keyword in the example above, the output would be “0” instead of “5”.
this
can also be used to:
- Invoke current class constructor
- Invoke current class method
- Return the current class object
- Pass an argument in the method call
- Pass an argument in the constructor call
you can refer to this or further explanation
https://www.javatpoint.com/this-keyword
mark your doubt as resolved if u are satisfied