本帖最后由 张卯 于 2012-4-15 21:49 编辑
- package cn.itcast.day1;
- import java.util.Date;
- 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(WeekDay.valueOf("SUN").toString());
- System.out.println(WeekDay.values().length);
-
- new Date(300){};[color=Green]//这句什么意思?没弄明白。[/color]
- }
-
- public enum WeekDay{
-
- SUN(1),MON,TUE,WED,THI,FRI,SAT;//分号可以有也可以没有。
- private WeekDay(){System.out.println("first");}
- private WeekDay(int day){System.out.println("second");}
- }
-
- public enum TrafficLamp{
- RED(30){
- @Override
- public TrafficLamp nextLamp() {
- // TODO Auto-generated method stub
- return GREEN;
- }
-
- },
- GREEN(45){
- @Override
- public TrafficLamp nextLamp() {
- // TODO Auto-generated method stub
- return YELLOW;
- }
-
- },
- YELLOW(5){
- @Override
- public TrafficLamp nextLamp() {
- // TODO Auto-generated method stub
- return RED;
- }
-
- };
- public abstract TrafficLamp nextLamp();
- private int time;
- private TrafficLamp(int time){this.time = time;}
- }
- }
复制代码 代码来源于“16_黑马程序员_张孝祥_Java基础加强_实现带有抽象方法的枚举”。
语句位于22行:new Date(300){};//这句什么意思?没弄明白。
不知道为什么颜色没设置成功~ |