public class SingletonTest
{
public static void main(String[] args)
{
Singleton singleton = Singleton.getinstance();
Singleton singleton1 = Singleton.getinstance();
System.out.println(singleton == singleton1);
}
}
class Singleton
{
// private static Singleton singleton ;
private static Singleton singleton = new Singleton();
private Singleton()
{
}
public static Singleton getinstance()
{
// if(singleton == null)
// {
// singleton = new Singleton();
// }
return singleton;
}
}
{
public static void main(String[] args)
{
Singleton singleton = Singleton.getinstance();
Singleton singleton1 = Singleton.getinstance();
System.out.println(singleton == singleton1);
}
}
class Singleton
{
// private static Singleton singleton ;
private static Singleton singleton = new Singleton();
private Singleton()
{
}
public static Singleton getinstance()
{
// if(singleton == null)
// {
// singleton = new Singleton();
// }
return singleton;
}
}