Good day colleagues!
In the literature they write that when a class is loaded, the static block is first executed, and then the dynamic block and the constructor. I managed to write a class so that the static block was executed last.
public class Singleton { static Singleton st = new Singleton(); static { //ΡΡΠ°ΡΠΈΡΠ΅ΡΠΊΠΈΠΉ Π±Π»ΠΎΠΊ System.out.println("Π‘ΡΠ°ΡΠΈΡΠ΅ΡΠΊΠΈΠΉ Π±Π»ΠΎΠΊ"); } { //Π°Π½ΠΎΠ½ΠΈΠΌΠ½ΡΠΉ Π±Π»ΠΎΠΊ System.out.println("ΠΠΈΠ½Π°ΠΌΠΈΡΠ΅ΡΠΊΠΈΠΉ Π±Π»ΠΎΠΊ"); } Singleton(){ //ΠΊΠΎΠ½ΡΡΡΡΠΊΡΠΎΡ System.out.println("ΠΠΎΠ½ΡΡΡΡΠΊΡΠΎΡ"); } public static void main(String[] args) { //ΠΡΡΡΠ°Ρ ΡΠΎΡΠΊΠ° Π²Ρ
ΠΎΠ΄Π° } } OUTPUT:
ΠΠΈΠ½Π°ΠΌΠΈΡΠ΅ΡΠΊΠΈΠΉ Π±Π»ΠΎΠΊ ΠΠΎΠ½ΡΡΡΡΠΊΡΠΎΡ Π‘ΡΠ°ΡΠΈΡΠ΅ΡΠΊΠΈΠΉ Π±Π»ΠΎΠΊ Question: How to explain the observed behavior?