Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Final variables

 
Bharadwaj Adepu
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In the above code the constructor is setting a value to the final variable name.
How is that possible? This runs fine and prints FINAL VARIABLE!
Please explain.
 
Campbell Ritchie
Sheriff
Posts: 48406
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A final field or variable can be set up once and once only. That can be done at declaration, in an initialiser (fields only) or in the constructor (again fields only).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic