单台设计模式的一个小程序!求解!!
class TextSingle
{
private static final TextSingle onlyOne=new TextSingle();
private static int count=0;
TextSingle()
{
count++;
System.out.println("the objective has setuped and "+"count="+count);//运行时为count=1.[\b]
}
public static TextSingle getTextSingle()
{
return onlyOne;
}
public int createObjNumber()
{
System.out.println("count="+count);//[b]运行时为count=1?不解
return count;
}
}
public class scope31
{
public static void main(String[]args)
{
System.out.println("the number of the objective is "+TextSingle.getTextSingle().createObjNumber());//这个运行结果为count=1?
}
}
问题就是程序中的三个注释部分为什么最后一count运行出来是0呢??不解!!!