enumAccountType{
SAVING, FIXED, CURRENT;
privateAccountType(){
System.out.println(“It is a account type”);
}
}
classEnumOne{
publicstaticvoidmain(String[]args){
System.out.println(AccountType.FIXED);
}
}
輸出結(jié)果:
It is a account type
It is a account type
It is a account type
FIXED
枚舉類 所有的枚舉值都是類靜態(tài)常量,在初始化時(shí)會(huì)對(duì)所有的枚舉值對(duì)象進(jìn)行第一次初始化驻债。