枚举类(二)

枚举类

/*

 * 通过JDK5提供的枚举来做枚举类

 */

public enumDirection3 {

   FRONT("") {

      @Override

      public void show() {

         System.out.println("");

      }

   },

   BEHIND("") {

      @Override

      public void show() {

         System.out.println("");

      }

   },

   LEFT("") {

      @Override

      public void show() {

         System.out.println("");

      }

   },

   RIGHT("") {

      @Override

      public void show() {

         System.out.println("");

      }

   };

 

   private String name;

 

   private Direction3(String name){

      this.name = name;

   }

 

   public String getName() {

      return name;

   }

 

   public abstract void show();

}

 

public classDirectionDemo {

   public static void main(String[] args) {

  

      Direction3d3 = Direction3.FRONT;

      System.out.println(d3);

      System.out.println(d3.getName());

      d3.show();

      System.out.println("--------------");

 

      Direction3dd = Direction3.FRONT;

      dd= Direction3.LEFT;

 

      switch (dd) {

      case FRONT:

         System.out.println("你选择了前");

         break;

      case BEHIND:

         System.out.println("你选择了后");

         break;

      case LEFT:

         System.out.println("你选择了左");

         break;

      case RIGHT:

         System.out.println("你选择了右");

         break;

      }

   }

}

运行结果:

FRONT

--------------

你选择了左

 


你可能感兴趣的:(枚举类)