enum
AccountType
{
SAVING, FIXED, CURRENT;
private
AccountType()
{
System.out.println(“It is a account type”);
}
}
class
EnumOne
{
public
static
void
main(String[]args)
{
System.out.println(AccountType.FIXED);
}
}
输出结果是:
It is a account type
It is a account type
It is a account type
FIXED
枚举类 所有的枚举值都是类静态常量,在初始化时会对所有的枚举值对象进行第一次初始化。