枚举
1. 构造函数,要放在 枚举对象 列表之后。
2. 构造函数,必须是私有的。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public enum MyEnum
{
MON(1, "星期一"), TUE(2, "星期二");
int a;
String b;
// 构造函数必须私有
private MyEnum(){};
private MyEnum(int _a, String _b)
{
this.a = _a;
this.b = _b;
}
public void setA(int _a)
{
this.a = _a;
}
public static void main(String[] args)
{
for(MyEnum myEnum : MyEnum.values())
{
System.out.println(myEnum);
}
}
}
{
MON(1, "星期一"), TUE(2, "星期二");
int a;
String b;
// 构造函数必须私有
private MyEnum(){};
private MyEnum(int _a, String _b)
{
this.a = _a;
this.b = _b;
}
public void setA(int _a)
{
this.a = _a;
}
public static void main(String[] args)
{
for(MyEnum myEnum : MyEnum.values())
{
System.out.println(myEnum);
}
}
}