When to use this. And when not to use it
How to use this
no no my question is when we create a constructor we use, this.capacity etc, so my question is when it is important to use this and when we can ignore using this.name=name thing…
@nishantrocks1997_f40e121684ea6000 if in case you have the same name class variable and local variable(parameter of a method) then to specify that you’re using a class variable you will use this for example :
if your class was having capacity variable in the constructor you have to assign the capacity given in the constructor to capacity in a class variable. Therefore you use this.capacity(class variable) = capacity(Constructor parameter);Note this is not an exact code parenthesis are used for explanation. For further knowledge on this keyword refer article below :
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.