// When the class is loaded, the static block gets executed once
class StaticAndConstructor {
static int a;
public StaticAndConstructor() {
System.out.println("CONSTRUCTOR");
}
// static block
static {
System.out.println("static block");
a = 111;
}
public void show() {
System.out.println(a);
}
}
public class Program {
public static void main(String[] args) {
StaticAndConstructor sac1 = new StaticAndConstructor();
StaticAndConstructor sac2 = new StaticAndConstructor();
StaticAndConstructor sac3 = new StaticAndConstructor();
sac1.show();
sac2.show();
sac3.show();
}
}
/*
run:
static block
CONSTRUCTOR
CONSTRUCTOR
CONSTRUCTOR
111
111
111
*/