Question 7 Which of the following statements are true? a. The value of a final field can not be assigned more than once. b. The value of a final field can be assigned at any time or not at all. c. A final field that is not assigned a value at compile time is called a blank final variable. d. Only static variables can be declared final. e. A blank final variable that is static must be definitely assigned in a static initializer. f. By the end of the instance construction process all blank final instance variables must be definitely assigned. g. A field can not be declared both final and volatile. h. None of the above.
One of the correct answers listed is c. I would agree if a final field referes to an instance final field only. Not true for final static field.
Steve Lovelace
Ranch Hand
Joined: Sep 03, 2003
Posts: 125
posted
0
I agree with Barkat but would go further. A blank final is a final variable whose declaration lacks an initializer. - JLS 4.5.4 Many final fields have initializers which execute at run time. They are not blank finals AND the compiler does not assign values to them. So answer c is just plain false.