I am not sure but remember of reading somewhere that "final variable must be initialized before constructor ends(ie controls goes out of constructor)" So we can initialize it in a block or in contructor Correct me if I am wrong Megan
Hi Megan: I think you are right. If final is a member data field, it has to be initialized at the declaration or in a subsequent initilizer or at most in the constructor. Otherwise, when initialized in some other place, compiler will complain that value can not be assigned to a final variable. Interestingly, if you forget to initialize a final and NEVER use it in your code, it would compile and run fine. However, if final is method variable, you can initialize it before its first use.... Thanks Barkat
Joined: Aug 26, 2002
Another thing, you can't initialize a class-level final variable in both the initializer block and constructor.
It will complain about: "variable i might already have been assigned to" in line 7.
Joined: Aug 05, 2002
I thinks rule about any (class level, method level, within an argument) final variable is that they can be assigned only once.