What is singleton class?
Answer Posted / marshallsudhan
singleton class - has single Instance.
The Singleton is a useful Design Pattern for allowing only
one instance of your class, but common mistakes can
inadvertently allow more than one instance to be created.
The Singleton's purpose is to control object creation,
limiting the number to one but allowing the flexibility to
create more objects if the situation changes. Since there
is only one Singleton instance, any instance fields of a
Singleton will occur only once per class, just like static
fields.
//Eg Pgm.
class Sample
{
void m1()
{
System.out.println("Method m1");
}
void m2()
{
System.out.println("Method m2");
}
private Sample()
{
System.out.println("Constructor");
}
public static void main(String[] args)
{
Sample s = new Sample();
s.m1();
s.m2();
}
Is This Answer Correct ? | 49 Yes | 74 No |
Post New Answer View All Answers
What are the differences between forwarding () method and sendredirect() methods?
Add a value x to array from index l to r where 0 <= l <= r <= n-1
What is the use of arraylist in java?
What is the old name of java?
What does mean in regex?
What is the difference between assignment and initialization?
What do you understand by a Static Variable?
What is early binding and late binding in java?
What are the advantages of unicode?
Can a class have multiple constructors?
What is use of set in java?
Why are the methods of the math class static?
Can we force the garbage collection to run?
Difference between final and effectively final ? Why is effectively final even required ?
What is a war file?