Dear All,
Enum is again troubling me
I have seen that we can overload a method in enums. Also, I have seen that we can define a method in an enum and overload the method (change the args) in constant specific body. This compiles fine. But when I try to call the method defined in consant specific body the compiler complains. Why is this so?
The following is my code. The line in bold creates the issue
public enum Seasons {
SUMMER(10),
WINTER {
public int getSeasonValue() {
return 100;
}
},
AUTUMN {
public int abc = 1999;
public int getSeasonValue(int x) {
return 20;
}
},
SPRING;
private int seasonValue;
Seasons(int x) {
seasonValue = x;
}
Seasons() {
}
public int getSeasonValue() {
return seasonValue;
}
public static void main(
String args[]) {
Season season = new Season();
System.out.println("SUMMER: "+season.seasonS.getSeasonValue());
System.out.println("WINTER: "+season.seasonW.getSeasonValue());
System.out.println("AUTUMN: "+season.seasonA.getSeasonValue(10));
}
}
class Season {
Seasons seasonS = Seasons.SUMMER;
Seasons seasonW = Seasons.WINTER;
Seasons seasonA = Seasons.AUTUMN;
}