//singleton notes
package niit1;
public class singleton
{
public static singleton mark=null;
public String java;
private singleton()
{
java="java 35";
}
public static singleton ask()
{
if(mark==null)
{
mark=new singleton();
}
return mark;
}
}
class sample13
{
public static void main(String nam[])
{
singleton s= singleton.ask();
singleton ss=singleton.ask();
System.out.println(s.java);
System.out.println(s.java);
}
}
defenition :
The singleton design pattern is used to restrict the instantiation of a class and ensures that only one instance of the class exists in the JVM. In other words, a singleton class is a class that can have only one object (an instance of the class) at a time per JVM instance.