Singleton class in Java and how can we make a class as singleton?

Singleton class is a class whose only one instance can be created at any given time in one JVM.

  • Make constructor as private, so that instance cannot be created outside the class.
  • Private static instance needs to be created in that class itself.
  • Static method should created a new instance if the value is null. Otherwise it should return the old instance. New instance creation will be avoided.

Leave a comment

Hey!

I’m Bedrock. Discover the ultimate Minetest resource – your go-to guide for expert tutorials, stunning mods, and exclusive stories. Elevate your game with insider knowledge and tips from seasoned Minetest enthusiasts.

Join the club

Stay updated with our latest tips and other news by joining our newsletter.