Hello,
Can someone explain why this static method is executed prior to the println
statements ? I don't understand how it gets called.
class Static {
static int b;
static int a = 3;
static void method(int x) {
System.out.println("x = " + x);
System.out.println("a = " + a);
System.out.println("b = " + b);
}
static { // how does this get called first ?
System.out.println("static block initialized");
b = a * 4;
}
public static void main(
String args[]) {
method(42); // Calls the method 'method' and passes 42 to 'int x'.
}
}
Prints out:
static block initialized
x = 42
a = 3
b = 12
Thanks
Todd