输出结果:
It is a account type
It is a account type
It is a account type
SAVING
It is a account type
It is a account type
SAVING
解释:简而言之,枚举类有是三个实例,故调用三次构造方法,打印三次It is a account type
2.
public class EnumIndexTest {
enum Constants2 {
Constants_A("枚举成员A"),
Constants_B("枚举成员B"),
Constants_C("枚举成员C"),
Constants_D(3);
private String description;
private int i = 4;
private Constants2() {
}
private Constants2(String description){
this.description = description;
}
private Constants2(int i) {
this.i = this.i + i;
}
public String getDescription() {
return description;
}
public int geti() {
return i;
}
}
public static void main(String[] args) {
for(int i = 0;i < Constants2.values().length;i++){