Good day colleagues! I have a very simple code:
public class Singleton { static Singleton st = new Singleton(); Singleton(){ System.out.println("ΠΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΡ "); } public static void main(String[] args) { } } The class contains one field - itself. The entry point is empty, nothing is created in Maine. Nevertheless, the constructor executes, displays to the console:
ΠΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΡ
Question: Why does a constructor work out and where can one read about it?
static Singleton stfield that is static, so when you load a class, this field is initialized with the value ofnew Singleton();. - learp