What is Singleton class?

No comments

Objects are created in run-time and are allocated in a memory area in JVM known as the
heap. There may be many objects of a single class. In some cases, we will want to have
one and only one instance of a class in the JVM. Such a class is said to be a singleton class.

To design a singleton class

•   We need to declare the reference variable of the class as private and static.

•   We need to make the default constructor of the class as private. In this way we can ensure that no other class can create an instantiate the object of this class outside the class body.

•   We provide a static member with a null check condition to access the one and only one instance of the class.

No comments :

Post a Comment

Subscribe

Milan Panda
Admin
About Me | Contact
Copyright 2023-2024 © Programming1011 . 🎀 Developed and Design By- Milan Panda. Happy Holi All Of You 🎀