本帖最后由 闫江龙 于 2011-12-31 19:25 编辑
public abstract class WeekDay1 {
private WeekDay1(){}
public final static WeekDay1 SUN = new WeekDay1(){
public WeekDay1 nextDay() {
return MON;
}
};
public final static WeekDay1 MON = new WeekDay1(){
public WeekDay1 nextDay() {
return SUN;
}
};
public abstract WeekDay1 nextDay();
public String toString(){
return this==SUN?"SUN":"MON";
}
}
public class EnumTest {
public static void main(String[] args) {
WeekDay1 weekDay = WeekDay1.MON;
System.out.println(weekDay.nextDay());//weekDay.nextDay()得到的是对象 但打印的时候却打印出的字符串,调用tostring()方法的原理是什么???都有什么情况会调用他?如果这样写呢weekDay.nextDay().tostring()
}
}
|