本帖最后由 黑马-王鹏 于 2013-5-7 17:30 编辑
- package cn.itcast.day1;
- public class EnumDemo {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
-
- Weekday weekday = Weekday.SUN;
- System.out.println(weekday.nextDay().toSting());
- }
- }
复制代码- package cn.itcast.day1;
- public abstract class Weekday {
- private Weekday(){}
- public final static Weekday SUN = new Weekday(){
- @Override
- public Weekday nextDay() {
- // TODO Auto-generated method stub
- return MON;
- }
- };
- public final static Weekday MON = new Weekday(){
- @Override
- public Weekday nextDay() {
- // TODO Auto-generated method stub
- return SUN;
- }
-
- };
- public abstract Weekday nextDay();
- /*{
- if(this == SUN)
- return SUN;
- else {
- return MON;}
- }*/
- public String toSting(){
- return this == SUN?"MON":"SUN";
- }
- }
复制代码 为什么我运行结果是SUN?按照视频里张老师运行的应该是MON才对啊。
|
|