Use and flow of Static statements in Singleton Program

后端 未结 6 589
面向向阳花
面向向阳花 2021-01-14 13:29

I know there are lot of questions on Singleton pattern. But here what I would like to know about the output which might also cover how \"static\" works in Java.



        
6条回答
  •  逝去的感伤
    2021-01-14 13:54

    Class gets loaded and initialized first by classloader of JVM. And JVM while initializing, scans the class (Singleton) and while doing that it initializes static variable which is in the first line. That variable calls the constructor and prints line in it. Once class is initialized, it will invokes main method and hence prints the statement inside it.

提交回复
热议问题