码迷,mamicode.com
首页 > 其他好文 > 详细

带有构造方法的枚举

时间:2017-05-07 12:52:34      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:amp   enum   sys   imp   int   return   stat   name   cal   

/****
* 带有构造方法的枚举
* @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;
}
}
}

 

带有构造方法的枚举

标签:amp   enum   sys   imp   int   return   stat   name   cal   

原文地址:http://www.cnblogs.com/chenyanlong/p/6820236.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!