集册 Java实例教程 开启枚举

开启枚举

欢马劈雪     最近更新时间:2020-01-02 10:19:05

622
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
开启枚举
/** from nowjava - 时  代  Java**/

enum Day {

    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY

}


public class EnumTest {

    Day day;


    public EnumTest(Day day) {

        this.day = day;

    }


    public void tellItLikeItIs() {

        switch (day) {

        case MONDAY:

            System.out.println("Mondays are bad.");

            break;


        case FRIDAY:

            System.out.println("Fridays are better.");

            break;


        case SATURDAY://from 时   代     Java  公  众  号 - nowjava.com

        case SUNDAY:

            System.out.println("Weekends are best.");

            break;


        default:

            System.out.println("Midweek days are so-so.");

            break;

        }

    }


    public static void main(String[] args) {

        EnumTest firstDay = new EnumTest(Day.MONDAY);

        firstDay.tellItLikeItIs();

        EnumTest thirdDay = new EnumTest(Day.WEDNESDAY);

        thirdDay.tellItLikeItIs();

        EnumTest fifthDay = new EnumTest(Day.FRIDAY);

        fifthDay.tellItLikeItIs();

        EnumTest sixthDay = new EnumTest(Day.SATURDAY);

        sixthDay.tellItLikeItIs();

        EnumTest seventhDay = new EnumTest(Day.SUNDAY);

        seventhDay.tellItLikeItIs();

    }

}


展开阅读全文