Search code examples
javastaticcall

java - When is static {} called?


Take, for example, this class:

public class Example {
    static {
        // Do something
    }
}

When exactly is the static block called?


Solution

  • The static initializer block is called once, when the class is initialized. It is generally used to initialize static members of the class.