|
|
| java |
Expert:jagan
what is a singleton class? why and where we used and give me one example |
| Answers |
hai friend this is jagadhish
A singleton is a class that can be instantiated only one time in JVM pet class loader.Repeated calls always return the same instance.Ensures that a class has only one instance,and provide a global point of access.it can be an issue if singleton class gets loaded by multiple class loaders.
EXAMPLE FOR THIS SINGLETON JAVA CLASS
public class OnlyOne{ private static OnlyOne one=new OnlyOne(); private OnlyOne{//private constructor.This class cannot be instantiated from outside. .................. } public static OnlyOne getInstance(){ return one; } }
To use it: //No matter how many times you get the same instance of the object OnlyOne myOne=OnlyOne.getInstance();
Thank you friend
|
| More Questions |
|
|
Post Answers
Ask Question
Facing Programming Problem?
|
|
|
|
|