- public class Test27 {
- //自定义枚举week表示星期几,要求每个枚举值都有tolocaleString方法。返回中文格式的星期几。
- public static void main(String[] args)throws Exception {
- // TODO Auto-generated method stub
- System.out.println(WeekDay.MON.toLocaleString());
- }
- public enum WeekDay{
-
- MON{
- public String toLocaleString() {
- return "星期一";
- }},
- TUE{
- public String toLocaleString() {
- return "星期二";
- }},
- WEN{
- public String toLocaleString() {
- return "星期三";
- }},
- THU{
- public String toLocaleString() {
- return "星期四";
- }},
- FRI{
- public String toLocaleString() {
- return "星期五";
- }},
- SAT{
- public String toLocaleString() {
- return "星期六";
- }},
- SUN{
- public String toLocaleString() {
- return "星期日";
- }};
-
- public abstract String toLocaleString();
- }
- }
复制代码 |
|