DEV Community

Jefferson Huisa
Jefferson Huisa

Posted on

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.

Top comments (0)