In what order do static blocks and initialization blocks execute when using inheritance?

I learn visually, so here’s a visual representation of order, as a SSCCE: public class Example { static { step(1); } public static int step_2 = step(2); public int step_8 = step(8); public Example(int unused) { super(); step(10); } { step(9); } // Just for demonstration purposes: public static int step(int step) { System.out.println(“Step ” … Read more

Static Initialization Blocks

The non-static block: { // Do Something… } Gets called every time an instance of the class is constructed. The static block only gets called once, when the class itself is initialized, no matter how many objects of that type you create. Example: public class Test { static{ System.out.println(“Static”); } { System.out.println(“Non-static block”); } public … Read more