The result is:
1
3
1
3
1
3
2
The constructor runs for A,B and for C (3 times). But if you use static keyword it runs only once. What is the reason of this? And why does this line executes last?
enum Enums {
A, B, C;
{
System.out.println(1);
}
static {
System.out.println(2);
}
private Enums() {
System.out.println(3);
}
}
public class MainClass{
public static void main(String[] args) {
Enum en = Enums.C;
}
}