I'm declaring a static variable after static block. When I'm calling a method to print its value, the result is 0. I decompiled the .class file and found that the structure of the static block has changed. Can anyone please explain why?
class Testing {
static {
callMe();
System.out.println("Static finished");
}
static void callMe() {
System.out.println(x);
}
static int x = 10;
public static void main(String[] args) {
System.out.println("Complete");
}}
Decompiled code :
class Testing {
static int x;
Testing() {
}
static void callMe() {
System.out.println(x);
}
public static void main(String[] args) {
System.out.println("Complete");
}
static {
callMe();
System.out.println("Static finished");
x = 10;
}}