Singleton Design pattern?

S

seshireddy

class must be create only one instance ctreation(Object creation
irrespective any number of objects are createad on that class
ForEx:
public class Employee
{
public Employee()
{
System.out.println("Employee Object is createad");
}
}
public class Singleton
{
private staticSingleton var=null;
private Singleton()
{
System.out.println("Singleton constracter");
}
public static Singleton Method()
{
if(var==null)
{
new Singleton();
}
}
public static void main(String aa[])
{
Singleton s1,s2,s3,s4;
s1=Singleton.Method();
s2=Singleton.Method();
s3=Singleton.Method();
s4=Singleton.Method();
System.out.println(s1.hascode());
System.out.println(s2.hascode());
System.out.println(s3.hascode());
System.out.println(s4.hascode());
}
}

output:
=====
only one adress is createa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top