• 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

Initializing a static variable

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going through the HFJ chapter that deals with staic variables and I have a question about initialization. HFJ gives the following code.


I understand this code and the use of the static initalizer, but I'm confused as to the next block of code.


HFJ states that this second code example will generate a compiler error that


I confused becuase on the previous page they stated that
"Defualt values for declared but uninitialized static and instance variables are the same:
primitive integers (long, short, etc.): 0
primitive floating point (float, double):0.0
etc..."

So in the case of the second block of code, why is the compiler complaining, should'nt BAR_SIGN be initialized to the default (0.0)?

edited 5/15 - error correction
[ May 15, 2005: Message edited by: Bob Beerbower ]
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, since it's final, you have to specifically initialize it to a value.
 
Bob Beerbower
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James,
Thanks for the reply. If I'd kept on reading HFJ gave me the same answer a few pages latter. Thanks again.
reply
    Bookmark Topic Watch Topic
  • New Topic