I wonder how java initializes these static variables. Code that I cannot understand is shown by a hit:
public class Main {
static int first=test();
static int second=2;
static int third=test();
public static void main(String[] args) {
System.out.println(first);
System.out.println(second);
System.out.println(third);
}
public static int test() {
return second;
}
}
The result of the simple code below: 0 2 2
Should the compiler automatically ignore the non-executable method or is the static variable equal to 0 before it determines?
Sorry, you cannot find the exact description for Google.
source
share