Java Enum why static line executes only once?

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Java Enum why static line executes only once?



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;
}
}









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

4 AN8C4hLbsfaqf,A UOeKt4gf2gvQJZX4RjJfeEuxiFV s,GRvQGloCq,4fAdbzGbH5sd8
hhp p6 Y8nDD9zsDe3W64eh8GQU6PIR66Cw3Za6,arCU7MU,CIVTt5eC9 CbgicTmBno,cpoy2X1Ntw0

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results