Hello All,
I'm a first time poster, long time browser, hoping for clarification on enum declarations. In prep exams I'm taking before I sit for the
SCJA, questions regrading enums are coming up that are leaving me a little confused.
To be specific, it is all about the semi-colon.
In one question the correct answer given for an enum declaration is as follows:
enum Grade{a,b,c,d};
However, in another it states that the following code will compile and run, outputting GOLDFISH:
class
Test {
enum Fish{GOLDFISH, ANGELFISH, GUPPY}
public static void main(
String args[]){
System.out.println(Fish.GOLDFISH);
}
}
In this code the semi-colon following the enum declaration is not present.
I had intitially thought the semi-colon was used when an enum declaration was within a class, and not used when it was a stand alone declaration in a file by itself, but the code above disproves that theory.
So my question boils down to this: Can anyone explain to me when and where the semi-colon is required for an enum declaration to be legal?
Thanks in advance,
Geoff