类season是公共的,应在名为season.java的文件中声明 5
刚学Java在做枚举的时候的一个代码总是没法运行求帮助publicenumSeason{SPRING,SUMMER,AUTUMN,WINTER}publicclassEn...
刚学Java 在做枚举的时候的一个代码 总是没法运行 求帮助
public enum Season{
SPRING, SUMMER, AUTUMN, WINTER
}
public class EnumDemo{
Season season;
public EnumDemo(Season season){
this. season = season;
}
public void saySeason(){
switch(season){
case SPRING: System.out.println("it is spring");
break;
case SUMMER: System.out.println("it is summer");
break;
case AUTUMN: System.out.println("it is autumn");
break;
default: System.out.println("it is winter");
break;
}
}
public class Test{
public void main(String[] args) {
EnumDemo SPRING = new EnumDemo(Season.SPRING);
SPRING. saySeason();
EnumDemo SUMMER = new EnumDemo(Season.SUMMER);
SUMMER. saySeason();
EnumDemo AUTUMN = new EnumDemo(Season.AUTUMN);
AUTUMN. saySeason();
EnumDemo WINTER = new EnumDemo(Season.WINTER);
WINTER. saySeason();
}
}
} 展开
public enum Season{
SPRING, SUMMER, AUTUMN, WINTER
}
public class EnumDemo{
Season season;
public EnumDemo(Season season){
this. season = season;
}
public void saySeason(){
switch(season){
case SPRING: System.out.println("it is spring");
break;
case SUMMER: System.out.println("it is summer");
break;
case AUTUMN: System.out.println("it is autumn");
break;
default: System.out.println("it is winter");
break;
}
}
public class Test{
public void main(String[] args) {
EnumDemo SPRING = new EnumDemo(Season.SPRING);
SPRING. saySeason();
EnumDemo SUMMER = new EnumDemo(Season.SUMMER);
SUMMER. saySeason();
EnumDemo AUTUMN = new EnumDemo(Season.AUTUMN);
AUTUMN. saySeason();
EnumDemo WINTER = new EnumDemo(Season.WINTER);
WINTER. saySeason();
}
}
} 展开
1个回答
2014-12-21
展开全部
这些类,都写在一个文件里面?那只有season类写成public class、别的就不要写public——只写class
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询