• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dan's Mock: Field declaration Q 7

 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic