Hi all,
The following code will give
1: public class Q8
2: {
3: int i = 20;
4: static
5: {
6: int i = 10;
7:
8: }
9: public static void main(
String[] args)
10: {
11: Q8 a = new Q8();
12: System.out.println(a.i);
13: }
14: }
A) Compilation error, variable "i" declared twice.
B) Compilation error, static initializers for initialization purpose only.
C) Prints 10.
D) Prints 20.
The answer is 20. My question is, for those variables that are within static initializer, do they need to be declared as static as well? "i" in the above case is a non-static variable. but it should exist since it's initialized the frist time in the static initialization.
lydia