枚举类: package test; public enum Transport { /** car */ CAR(65), /** truck */ TRUCK(55), /** airplane */ AIRPLANE(600), /** train */ TRAIN(70), /** boat */ BOAT(22); /** speed of transport */ private int speed; /** constructor */ private Transport(int s) { speed = s; } /** * get speed of transport * * @return the speed */ public int getSpeed() { return speed; } } 程序入口: package test; public class App { /** * main * * @param args */ public static void main(String[] args) { /* get all transport of Transport Enum */ for (Transport tp : Transport.values()) { System.out.println(tp.name() + " : speed->" + tp.getSpeed()); } } } 输出: //CAR : speed->65 //TRUCK : speed->55 //AIRPLANE : speed->600 //TRAIN : speed->70 //BOAT : speed->22