Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

the "this" factor

 
shivang sarawagi
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between


&

 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is used to indicate the instance variable which is a good coding style.
Your sample code has different variable names. But consider if you have something AB(int pi)
Inside the constructor if you say pi, it will indicate the constructor argument, whereas this.pi indicates the instance variable
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic