Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java - When is static {} called? [duplicate]

Tags:

java

static

call

Take, for example, this class:

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

When exactly is the static block called?

like image 977
MCMastery Avatar asked Sep 01 '25 18:09

MCMastery


1 Answers

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

like image 158
Eran Avatar answered Sep 04 '25 06:09

Eran