public class WeekDay{html
private WeekDay(){};
app
public static final WeekDay SUN=new WeekDay();//類的實例
ide
public static final WeekDay MON=new WeekDay();this
}
spa
調用:htm
WeekDay sun=WeekDay.SUN;
blog
public enum EnumTest {get
MON(1), TUE(2), WED(3), THU(4), FRI(5), SAT(6) {class
@Override原理
public boolean isRest() {
return true;
}
},
SUN(0) {
@Override
public boolean isRest() {
return true;
}
};
private int value;
private EnumTest(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public boolean isRest() {
return false;
}
}
public class Test {
public static void main(String[] args) {
System.out.println("EnumTest.FRI 的 value = " + EnumTest.FRI.getValue());
}
}
輸出結果:
EnumTest.FRI 的 value = 5
http://www.cnblogs.com/happyPawpaw/archive/2013/04/09/3009553.html