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:
- Make constructor as private.
- Write a static method that has return type object of this singleton class.