Calling a Java method with no name

后端 未结 8 1435
迷失自我
迷失自我 2020-11-28 02:34

I\'m looking at the code below and found something a bit strange:

public class Sequence {
    Sequence() {
        System.out.print(\"c \");
    }

    {
            


        
8条回答
  •  情书的邮戳
    2020-11-28 02:42

    It is used as an initialisation block and runs after any static declaration. It could be used to ensure that no one else can create an instance of the class (In the same way you would use a private constructor) as with the Singleton design pattern.

提交回复
热议问题