- package cn.itcast.day1;
- public class WeekDay {
- private WeekDay(){}
- public final static WeekDay SUN=new WeekDay();
- //这是什么意思,为什么可以在本类中直接new呢?为什么不直接定义一个String常量呢?
- //为什么要定义成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";
- }
- }
复制代码 |