3

Take, for example, this class:

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

When exactly is the static block called?

MCMastery
  • 2,979
  • 2
  • 17
  • 42

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
  • 374,785
  • 51
  • 663
  • 734
2

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

Razib
  • 10,521
  • 10
  • 50
  • 75