实现带有构造方法的枚举

package com.hbsi.day1;


public class EnumTest {


/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WeekDay1 weekDay = WeekDay1.MON;
System.out.println(weekDay.nextDay());

WeekDay weekDay2 = WeekDay.FRI;
System.out.println(weekDay2);
System.out.println(weekDay2.name());
System.out.println(weekDay2.ordinal());
System.out.println(weekDay2.getClass());
System.out.println(WeekDay.valueOf("SUN").toString()); 
System.out.println(WeekDay.values().length);
}

public enum WeekDay{

//sun(1)指明调用带有一个参数的构造方法

SUN(1),MON(),TUE,WED,THI,FRI,SAT; 
private WeekDay(){
System.out.println("first");
}
private WeekDay(int day){
System.out.println("second");
}
}

}

你可能感兴趣的:(JAVA)