枚举类初始化

enumAccountType{
  SAVING, FIXED, CURRENT;
  privateAccountType(){
  System.out.println(“It is a account type”);
  }
}

classEnumOne{
    publicstaticvoidmain(String[]args){
    System.out.println(AccountType.FIXED);
  }
}

输出结果:
It is a account type
It is a account type
It is a account type
FIXED
枚举类 所有的枚举值都是类静态常量,在初始化时会对所有的枚举值对象进行第一次初始化。

你可能感兴趣的:(枚举类初始化)