我去,第一遍没感觉,第二遍,好像不懂,第三遍,好像很多不懂。张老师的一个枚举小视频看了N遍。。我想问一下一个小问题。- public class lianxi {
- public static void main(String[] args){
- WeekDay weekDay =WeekDay.MON;
- System.out.println(weekDay.nextDay());//再这输出语句写weekDay.nextDay().toString()跟在下面的类中定义toString意义怎么不一样呢????
- }
- }
复制代码- public abstract class WeekDay {
- private WeekDay(){}
- public final static WeekDay SUM=new WeekDay(){
- @Override
- public WeekDay nextDay() {
- return MON;
- }
-
- };
- public final static WeekDay MON=new WeekDay();
- public abstract WeekDay nextDay();
- public String toString(){
- return this==SUM?"SUM":"MON";
- }
- }
复制代码 |
|