4

Take, for example, this class:

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

When exactly is the static block called?

2
  • Ah yes, sorry. I looked this up but for some reason I could not find anything. Commented May 17, 2015 at 18:38
  • stackoverflow.com/questions/12550135/… Commented May 17, 2015 at 18:51

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.