Check this singleton design pattern explained with programs and steps

public class Singleton {

static Singleton obj;
private  Singleton(){
}

public static Singleton getInstance(){
if(obj!=null){
return  obj;
}
else{
obj=new Singleton();
return obj;
}
}

public static void main(String[] args) {

Singleton obj=Singleton.getInstance();
Singleton obj1=Singleton.getInstance();

if(obj==obj1){
System.out.println("indhu");
}
else{
System.out.println("Sindhu");
}
               System.out.println(obj==obj1);

}
}


Output:
indhu
true

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu