- public class EnumTest {
- public static void main(String[] args) {
- WeekDay weekDay = WeekDay.SUN;
- System.out.println(weekDay.nextDay());
- }
- }
- class WeekDay {
- private WeekDay(){}
-
- public final static WeekDay SUN = new WeekDay();
- public final static WeekDay MON = new WeekDay();
-
- public WeekDay nextDay(){
- if(this == SUN){
- return MON;
- } else {
- return SUN;
- }
- }
-
- public String toString(){
- return this == SUN ? "SUN" : "MON";
- }
- }
复制代码
应该是打印出对象的形式啊,为什么会打印出 “MON”? |