Use and flow of Static statements in Singleton Program

后端 未结 6 583
面向向阳花
面向向阳花 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 14:04

    Before the control gets to main() method, the class needs to be initialized. Since you initialize the currentSingleton inline with declaration, this initialization takes place before main(), during class loading.

提交回复
热议问题