class Single
{
private Single(){}
private static Single s = new Single();
public static Single getSingle()
{
return s;
}
}
class SingleDemo{
public static void main(String[] args)
{
single ss=Single.getInstance();//如果Single s = new Single();不是静态的,当多个像ss的类变量=Single.getInstance()时就会在堆内存
中开辟空间,就会出现内存溢出
} |