- public class EnumTest {
- public static void main(String[] args) {
- for (Color c : Color.values()) {
- System.out.println("c:" + c);
- System.out.println("c.name():" + c.name());
- System.out.println("c.ordinal():" + c.ordinal());
- System.out.println("c.getColorName()<span style="line-height: 2.2em; background-color: rgb(255, 255, 255);">:</span><span style="line-height: 2.2em;">" + c.getColorName());</span>
复制代码 输出结果:
c:RED
c.name():RED
c.ordinal():0
c.getColorName():红色
---------------------------------------
c:GREEN
c.name():GREEN
c.ordinal():1
c.getColorName():红色
---------------------------------------
c:BLUE
c.name():BLUE
c.ordinal():2
c.getColorName():红色
---------------------------------------
结论:就是为了重写
|