- /**
- * 2013-8-2下午12:35:37
- * EnumTest.java
- * Administrator
- */
- package com.itheima.test;
- /**
- * @author Administrator
- * @time 2013-8-2下午12:35:37
- */
- public class EnumTest {
- public static void main(String[] args) {
- Lamp red=Lamp.RED;
- //enum里面有抽象方法时,enum元素是其一个内部匿名子类对象,其父类是enum
- System.out.println(red.getClass().toString());
- System.out.println(red.getClass().getSuperclass().toString());
- Lamp1 red1=Lamp1.RED;
- //没有抽象方法时,enum元素是就是该enum的一个对象,父类是Enum
- System.out.println(red1.getClass().toString());
- System.out.println(red1.getClass().getSuperclass().toString());
-
- }
- }
- enum Lamp{
- RED{
- /* (non-Javadoc)
- * @see com.itheima.test.Lamp#getName()
- */
- @Override
- public String getName() {
- // TODO Auto-generated method stub
- return "red";
- }
- },GREED{
- /* (non-Javadoc)
- * @see com.itheima.test.Lamp#getName()
- */
- @Override
- public String getName() {
- // TODO Auto-generated method stub
- return "greed";
- }
- },YELLOW{
- /* (non-Javadoc)
- * @see com.itheima.test.Lamp#getName()
- */
- @Override
- public String getName() {
- // TODO Auto-generated method stub
- return "yellow";
- }
- };
- abstract public String getName();
- }
- enum Lamp1{
- RED,GREED,YELLOW
-
- }
复制代码 |