枚举基本用法

package 常用类;

public class TestEnum {

    public static void main(String[] args) {
        System.out.println(Season.SPRING);
        Season a=Season.AUTUMN; 
        switch(a){
        case SPRING:
            System.out.println("春天");
            break;
        case SUMMER:
            System.out.println("夏天");
            break;
        case AUTUMN:
            System.out.println("秋天");
            break;
        case WINTER:
            System.out.println("冬天");
        }
    }

    enum Season{
        SPRING,SUMMER,AUTUMN,WINTER;
    }
    
    enum Week{
        ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN
    }
}

结果:
SPRING
秋天

你可能感兴趣的:(枚举基本用法)