File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Final variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Final variables" Watch "Final variables" New topic

Final variables

Bharadwaj Adepu
Ranch Hand

Joined: Dec 30, 2007
Posts: 99

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.

SCJP 1.5
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 45255
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).
I agree. Here's the link:
subject: Final variables
It's not a secret anymore!