1. When there is no statement following the last enumeration item, ";" is optional. Well ,
String[] s = {"1","2"} where ";" is not necessary. I think the syntax of enum is similar to this array's syntax.
enum Weather{RAINY, Sunny} //compiles
enum Weather2{RAINY, Sunny;} //compiles
enum Weather3{RAINY, Sunny}; //compiles
2. When there is a statement following the last enumeration item, a ";" is needed, just like each statement must be followed by ";"
enum WeatherX{RAINY, Sunny;
int x;}
3. enum is a special type of class that extends Enum class. Sunny is an enum, which is an anonymous inner enum and declare variables. It is similar to defining anonymous inner class.
Inside the anonymous inner enum, you can define methods inside it.
enum Weather{RAINY, Sunny
{
void fx1(){}
}
}
4. Inside an enum, you can define a method, so that RAINY.fx1() can be called.
enum Weather{RAINY, Sunny;
void fx1(){}
}
5. There are two issues here. First, BIG(8) means we need a constructor of ICoffeeSize4. Similar to class , if you need an overloaded constructor if you want to create an object with some variable initialized.
Second, OVERWHELMING seems like an anonymous inner enum. Similar to anonymous inner class we cannot define any constructor for an anonymous inner class.
Correct me if I am wrong.