| Author |
Initializing a static variable
|
Bob Beerbower
Ranch Hand
Joined: Jun 06, 2001
Posts: 32
|
|
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 ]
|
Regards Bob Beerbower
|
 |
James Carman
Ranch Hand
Joined: Feb 20, 2001
Posts: 580
|
|
|
No, since it's final, you have to specifically initialize it to a value.
|
James Carman, President<br />Carman Consulting, Inc.
|
 |
Bob Beerbower
Ranch Hand
Joined: Jun 06, 2001
Posts: 32
|
|
James, Thanks for the reply. If I'd kept on reading HFJ gave me the same answer a few pages latter. Thanks again.
|
 |
 |
|
|
subject: Initializing a static variable
|
|
|