Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Final variables  RSS feed

 
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: 55280
156
  • 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
Boost this thread!