Status类声明三个对象属性,分别表示成员的状态,其中FREE-空闲、BUSY-已加入开发团队、VOCATION-正在休假
step1.声明status对象所需要的属性(构造器中要用到),用private final修饰(因为枚举类定义的是一组常量,它的属性也应该是常量)
private final String NAME;//设为私有的属性提供一下公共的get方法
//因为是final的,所以没有set方法
public String getNAME() {
return NAME;
}
step2.私有化类的构造器(枚举类的对象个数是确定的,所以构造器要私有化,不允许在外面再造对象,有点类似单例模式),并给对象属性赋值
private Status(String name) {
super();
this.NAME=name;
}
step3.提供当前枚举类的多个对象,设置为public static final的(可以通过类直接调用,并且为常量)
public static final Status FREE= new Status("FREE");
public static final Status VACATION=new Status("VACATION");
public static final Status BUSY=new Status("BUSY");