class Single
{
private int num;
private Single(){}
private static Single s=null;
public static Single getInstance()
{
if(s==null)
s=new Single();
return s;
}
public void setNum(int num)
{
this.num=num;
}
public int getNum()
{
return num;
}
class SingleDemo
{
public static void main(String[] args)
{
Single s1=Single.getInstance();
s1.setNum(20);
System.out.println("num="+s1.getNum());
}
}
SingleDemo.java:56: 错误: 进行语法分析时已到达文件结尾 为什么呢,把private static Single s=null;放类体第一行就行了?
|