package enum_movies;
public enum Show_Day
{
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;
}
Asked
Active
Viewed 106 times
-3

Jens
- 67,715
- 15
- 98
- 113

Ajeet Deginal
- 241
- 1
- 2
- 7
-
You might want to take a look at this thread http://stackoverflow.com/questions/18392885/java-definition-of-methods-and-variables-inside-enums-constant – Abhiroop Sarkar Sep 24 '14 at 04:49
-
Do you mean, why do you need to declare the enum constants before defining any methods? – Ted Hopp Sep 24 '14 at 05:01
-
Yes Ted, that's my question is. – Ajeet Deginal Sep 25 '14 at 10:13
-
my concern is only about, why constants has to be in first line!? why not any member at first line n later I will declare the constants? why the syntax is made like that? – Ajeet Deginal Oct 13 '14 at 05:06
1 Answers
1
Well, you don't have to. All the JLS requires is that there be an enum body with constants defined first, and it's legal for that body to only contain a semi-colon.
You could have an enum with all static methods in it like such...
public enum Baz {
;
public static void evilLaugh() {
System.out.println("BWAHAHA");
}
}
...but what's the point of an enumeration if there are no values to enumerate over?

Makoto
- 104,088
- 27
- 192
- 230
-
my concern is only about, why constants has to be in first line!? why not any member at first line n later I will declare the constants? why the syntax is made like that? – Ajeet Deginal Oct 13 '14 at 05:04
-
...Because the language specification said so. I believe I provided a link to the specific specification in my answer too... – Makoto Oct 13 '14 at 05:17