This is one of those "just-when-you-thought-you-knew-the-language" scenarios. I have a class in which the static block is not executing as expected. I've "dumbed down" the problem into three small classes that reproduce the issue:
public abstract class Parent {
static { System.out.println("In parent static block"); }
public static void call() { System.out.println("In Parent.call()"); }
}
public class Child extends Parent {
static { System.out.println("In child static block"); }
}
public class Test {
public static void main(final String[] args) {
Child.call();
}
}
When I call Test.main(), only the parent's static block is executed, not the child's. Does anyone understand why? Here's the ouput:
In parent static block
In Parent.call()