• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Initializing a static variable

 
Bob Beerbower
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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 ]
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic