Computer Science, asked by MaverickMani, 1 year ago

what is a singleton classes in java?

Answers

Answered by soyam4up90i2p
2
Here is your answer...

Singleton Class in Java

In object-oriented programming, a singleton class is a class that can have only one object (an instance of the class) at a time.
After first time, if we try to instantiate the Singleton class, the new variable also points to the first instance created. So whatever modifications we do to any variable inside the class through any instance, it affects the variable of the single instance created and is visible if we access that variable through any variable of that class type defined.
To design a singleton class:

Make constructor as private.

Write a static method that has return type object of this singleton class. Here, the concept of Lazy initialization in used to write this static method.

HOPE THIS HELPS YOU.
PLEASE MARK ME AS BRAINLIST
Similar questions