package com.ckp.my.java.test;
public class SystemExit {
public static void main(String[] args) {
// TODO Auto-generated method stub
// Sample sa=new Sample();
Sample sa=Sample.getInstance();
System.out.println("a="+sa.a);
System.out.println("b="+sa.b);
}
}
class Sample
{
static Sample sa=new Sample();
public static int a;
public static int b=0;
public static Sample getInstance()
{
return sa;
// return new Sample();
}
private Sample()
{
a++;
b++;
}
}
a=1;
b=0;
①set static variables default values. a=0;b=0;
②invoke static getInstance function to create a instance;
③invoke construct function and set a++,b++(at the moment ,a=0,b=0);
④at last,assigning values to variable. b=0.