java
class Frock{
private static int currentNum=100000;
private int serialNumber;
int getSerialNumber() {
return serialNumber;
}
public Frock() {
serialNumber = getNextNum();
}
public static int getNextNum(){
currentNum+=100;
return currentNum;
}
}
class TestFrock{
public static void main(String[] args) {
System.out.println(Frock.getNextNum());
System.out.println(Frock.getNextNum());
Frock f1=new Frock();
System.out.println(f1.getSerialNumber() );
Frock f2=new Frock();
System.out.println(f2.getSerialNumber() );
Frock f3=new Frock();
System.out.println(f3.getSerialNumber() );
}
}
结果: