当前位置:编程学习 > JAVA >>

java中的枚举

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){};
 }

 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){
   public  TrafficLamp nextLamp(){
    return GREEN;
   }
  },
  GREEN(45){
   public  TrafficLamp nextLamp(){
    return YELLOW;
   }   
  },
  YELLOW(5){
   public  TrafficLamp nextLamp(){
    return RED;
   }   
  };
  public abstract TrafficLamp nextLamp();
  private int time;
  private TrafficLamp(int time){this.time = time;}
 }
}


 

补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,