As far as i know this is used in following situations:
this
keyword is used when we want to refer to instance variable having same name as local variable.- Calling one constructor to other in same class.
- Pass the class instance as an argument to the method.
- Accessing the outer class variables.
But I have gone through my project code where they are using this in getters like:
class a{
int time;
int getValue(){
return this.time*5.;
}
}
As far as i know,every object has its own copy of instance variables and methods,so will returning this way makes any sense. Please clarify.
Stackoverfow problem referred:When should I use "this" in a class?
Aucun commentaire:
Enregistrer un commentaire