This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
It compiles and prints out '0'. Isn't it a forward reference at line 2 since p is not complete its initialization yet? Thanks for your explanation.
SCJP 1.4
Ron Newman
Ranch Hand
Joined: Jun 06, 2002
Posts: 1056
posted
0
p starts out with its default value (0). Line 2 is not a "forward reference" because it comes after line 1 in the source code.
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Yan Bai
Ranch Hand
Joined: Jul 21, 2002
Posts: 125
posted
0
Originally posted by Ron Newman: p starts out with its default value (0). Line 2 is not a "forward reference" because it comes after line 1 in the source code.
Thanks Ron. So how about final static variables, will they get a default value also? The following works, but does this mean that the value of final static variable can be changed?
Ron Newman
Ranch Hand
Joined: Jun 06, 2002
Posts: 1056
posted
0
It is indeed possible for a supposedly "final" static variable to change its value this way. I modified your code to the following:
which prints out: 0 123 I'd like to see the compiler generate a warning for cases like this, but it doesn't. [ October 31, 2002: Message edited by: Ron Newman ]