Lazy initialised Singletondesign Pattern.
This is java code for the lazy initialised singleton class . This is java code for
singleton design pattern . Which means that this class restrict to create multiple object
only one object of this class is possible.
public class LazySingleton {
private static LazySingleton instance;
private LazySingleton(){}
private static LazySingleton getInstance(){
if(instance == null){
instance = new LazySingleton();
}
return instance;
}
public void printHere(){
System.out.print("This is Singleton");
}
}
Use this singleton class as
public class Singletondesignpatten{
public static void main(String args){
LazySingleton.getInstance().printHere() ;
}
}
}
Out put of this program :--
This is singleton
Lazy initialised Singletondesign Pattern.
Reviewed by Mukesh Jha
on
6:56 AM
Rating:
No comments:
Add your comment