2 cike8899 cike8899 于 2013.10.28 19:24 提问

MON(){}是枚举的对象,怎么可以在里卖弄写方法呢?

package cn.itcast.enumeration2;

import org.junit.Test;

public class Demo2 {
@Test
public void test1(){

    System.out.println(Weekday.MON);
}

}
enum Weekday{
//MON,TUS,WED,THU,FRI,STA,SUN;
MON(){
public String week(){
return "星期一";
}
}
,TUS(){
public String week(){
return "星期二";
}
}
,WED(){
public String week(){
return "星期三";
}
}
,THU(){
public String week(){
return "星期四";
}
}
,FRI(){
public String week(){
return "星期五";
}
}
,STA(){
public String week(){
return "星期六";
}
}
,SUN(){
public String week(){
return "星期日";
}
};
public abstract String week();
}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!