本帖最后由 CHJ 于 2013-10-6 17:50 编辑
- public class EnumTest {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
-
- WeekDay weekDay = WeekDay.SUN;
-
- System.out.println(weekDay.nextDay());
- //为什么没调用toString()方法就打印出了字符串?
- }
- }
复制代码- public 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";
- }
- }
复制代码 //为什么没调用toString()方法就打印出了字符串?
|