集册 Java实例教程 枚举类型声明,它使用字段,构造函数和方法

枚举类型声明,它使用字段,构造函数和方法

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

461
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
枚举类型声明,它使用字段,构造函数和方法

public class Main {

  public static void main(String[] args) {/** 时 代      J a v a   公   众 号 - nowjava.com 提供 **/

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

      String name = s.name();

      int ordinal = s.ordinal();

      int days = s.getValue();  

      System.out.println("name=" + name + 

          ", ordinal=" + ordinal + ", days=" + days);

    }

  }

}

enum Level {

    LOW(30), MEDIUM(15), HIGH(7), URGENT(1);

    /*来 自 NowJava.com*/

    // Declare an instance variable  

    private int value;

    

    // Declare a private constructor  

    private Level(int a) {

        this.value = a;

    }

    

    
展开阅读全文