Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes final variable initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "final variable initialization" Watch "final variable initialization" New topic
Author

final variable initialization

vijayk kumar
Greenhorn

Joined: Jul 29, 2006
Posts: 18
Does a final variable initialized in overloaded constructors differently.
Then what about the necessity of intializing a variable at the declartion?
ramesh kumar
Greenhorn

Joined: Aug 15, 2006
Posts: 25
we can only initialize final variables once.
Tanka Banerjee
Ranch Hand

Joined: Aug 16, 2006
Posts: 64
Do it. final can't be reintialized
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I'm not sure what these guys are celebrating with their . But to answer the question in a useful way, there is no requirement to initialize a final variable at declaration. For an instance variable, the requirement is that it needs to be assigned before the constructor completes. If you want t assign a final variable in a constructor, you must not assign it at declaration, since a final variable may be assigned only once. vijayk, does that answer your question?


"I'm not back." - Bill Harding, Twister
Dana Bothner-By
Ranch Hand

Joined: Jul 28, 2006
Posts: 37
Hmmm... Your first sentense no verb.

Anyway, don't forget to assign a value in *every* constructor:
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

"rammy,"

Please see Henry's warning about your display name under this other post. Basically, we need a last name too. Thanks!

(So far, you've used in 100% of your posts. :roll: )


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Jim covered final fields. Final locals need never be assigned, but must be "definitely assigned" before they are used.


Tony Morris
Java Q&A (FAQ, Trivia)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: final variable initialization
 
Similar Threads
final variable question from kb
Regarding Inner Class
about final variable
Legal arguments in switch case statements
final instance variable