java实现自动递增序列号

本范例利用静态属性成员得到自动递增序列号的方法:
package org.test;

import java.text.DecimalFormat;

public class Customer {
	private static int totalCount = 0;
	private int customerID;
	public Customer(){
		++totalCount;
		customerID = totalCount;
		System.out.println("增加一个");
	}
	public String getCustomerID() {
	DecimalFormat decimalFormat = new DecimalFormat("00000000");
	return decimalFormat.format(customerID);
	}

}

package org.test;

public class Exec {
public static void main(String args[]){
	Customer c1 = new Customer();
	System.out.println(c1.getCustomerID());
	Customer c2 = new Customer();
	System.out.println(c2.getCustomerID());
}
}

你可能感兴趣的:(java)