4

Take, for example, this class:

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

When exactly is the static block called?

MCMastery
  • 3,099
  • 2
  • 20
  • 43

2 Answers2

4

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

Eran
  • 387,369
  • 54
  • 702
  • 768
2

The static initialization block is called when JVM load the class for the first time.

Razib
  • 10,965
  • 11
  • 53
  • 80