In which order static initialisation block and constructor run in java?
When the class loading and initialisation happens by JVM the static initialisation block gets executed. The constructor block is called at the every time of creating instance of that class.
class Practice { static { System.out.println("Static block."); } Practice() { System.out.println("Constructor block"); } public static void main(String...args) { Practice first = new Practice(); Practice second = new Practice(); } }
Output
// Static block // Constructor block // Constructor block