class chinese
{
static chinese example = new chinese();
static int count=1;
private chinese()
{
System.out.println(++count);
}
static
{
count=3;
System.out.println("static code");
}
public static chinese get()
{
return example;
}
}
class testchinese
{
public static void main(String[] args)
{
chinese ch1=chinese.get();
chinese ch2=chinese.get();
System.out.println(ch1==ch2);
}
}
为什么在执行这个程序时,count的返回值是1,还有为什么屏幕先显示的是1,而不是static code
完整的结果是
1
static code
ture