首页 > 代码库 > 带有构造方法的枚举
带有构造方法的枚举
/****
* 带有构造方法的枚举
* @author yanlong
* 2017/5/7
*/
package local;
public class EnumTest {
public static void main(String[] args){
WeekDay weekDay2=WeekDay.FRI;
System.out.println(weekDay2.name());
System.out.println(weekDay2.ordinal());
}
public enum WeekDay{
SUN(1),MON,TUS(3),WEN,THI,FRI,SAT;
private WeekDay(){System.out.println("first");}
private WeekDay(int day){System.out.println("second");}
}
}
————————————————————————————————————————————————————————
/****
* 带有构造方法的枚举
* @author yanlong
* 2017/5/7
*/
package local;
import java.sql.Date;
public class EnumTest {
public static void main(String[] args){
WeekDay weekDay2=WeekDay.FRI;
System.out.println(weekDay2.name());
System.out.println(weekDay2.ordinal());
new Date(300);
}
public enum WeekDay{
SUN(1),MON,TUS(3),WEN,THI,FRI,SAT;
private WeekDay(){System.out.println("first");}
private WeekDay(int day){System.out.println("second");
}
}
public enum TrafficLamp{
RED(30){
public TrafficLamp nextLamp(){
return GREEN;
}
},
GREEN(45){
public TrafficLamp nextLamp(){
return YELLOW;
}
},
YELLOW(5){
public TrafficLamp nextLamp(){
return RED;
}
};
private int time;
public abstract TrafficLamp nextLamp();
private TrafficLamp(int time){
this.time=time;
}
}
}
带有构造方法的枚举