+ 2

Why do have no change​ when I remove 'this'?

public void setAge(int a) { this.age = a; }

21st Apr 2017, 7:55 AM
HoangLoc
2 Réponses
+ 7
Because "this" represents the object itself so in the code above "this" represents to the object "age" so even if you remove that it is still the same
21st Apr 2017, 8:04 AM
MrCoder
MrCoder - avatar
+ 7
'this' keyword is used to point the object of current class. In your code it will remain same if you remove it though. If you do operator overloading kinda things. this will help you alot.
21st Apr 2017, 8:21 AM
Mr.Robot
Mr.Robot - avatar