What Is a Singleton in Java!

In OOP(Object Oriented Programming), a singleton class is a class that can have only one object at a time. After first time, if we try to instantiate the Singleton class, the new variable also points to the first instance created.

Key to remember while defining Singleton class:

  1. Make constructor as private.
  2. Write a static method that has return type object of this singleton class.

原文链接:What Is a Singleton in Java!

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容