java学习预先定义的常量 枚举类用法记录

public enum HeroType {

    TANK("春天"), WIZARD("夏天");

    String chineseName;

    HeroType(String chineseName) {

        this.chineseName = chineseName;

    }

    //自定义方法

   void getNews(){

        System.out.println(chineseName);

    }

}


    public static void main(String[] args) {

        HeroType herotype=HeroType.WIZARD;

        //调用自定义方法

        herotype.getNews();



      //遍历一个枚举都有哪些常量

        for (HeroType s : HeroType.values()) {

            System.out.println(s.chineseName);

        }
}

猜你喜欢

转载自blog.csdn.net/qq_39418742/article/details/112966063