本帖最后由 左华清 于 2012-2-24 17:19 编辑
package cn.itcast.day01;
public class EnumTest1 {
public static void main(String[]args){
WeekDay2 weekday=WeekDay2.SUN;
System.out.println(weekday.nextDay());
}
}
package cn.itcast.day01;
public class WeekDay2 {
private WeekDay2(){}
public static final WeekDay2 SUN=new WeekDay2();
public static final WeekDay2 MON=new WeekDay2();
public WeekDay2 nextDay(){
if(this==SUN){
return MON;
}else{
return SUN;
}
}
public String toString(){
if(this==SUN){
return "SUN";
}else{
return "MON";
}
}
}
打印的时候没有写 WeekDay2.toString()方法怎么就打印出了"MON",
这个是怎么运行的.不明白怎么调用了toString()方法. |