what is the result of the following code?
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);
}
}
Compiles fine and output is prints”It is a account type”thrice followed by”FIXED”
枚举类有三个实例,故调用三次构造方法,打印三次It is a account type
创建枚举类型要使用 enum 关键字,隐含了所创建的类型都是 java.lang.Enum 类的子类(java.lang.Enum 是一个抽象类)。枚举类型符合通用模式Class Enum