Given the following code:.
package mypkg;/*from w w w .java 2s.c om*/ enum Command {Compile, Test} // (1) public class Main { enum Command {Compile, Test} // (2) static enum Military { INFANTRY, AIRFORCE; enum Command {Compile, Test} // (3) } class Secret { enum Command {Compile, Test} // (4) } static class Open { enum Command {Compile, Test} // (5) } public static void declareWar() { enum Command {Compile, Test} // (6) } public void declarePeace() { enum Command {Compile, Test} // (7) }
Which enum declarations are not legal?.
Select the three correct answers.
(d), (f), and (g)
A nested enum type must be declared inside a static member type, like (2), (3) and (5).
Note that a nested enum type is implicitly static, and the keyword static is not mandatory in this case.
An enum type cannot be local, as static member types cannot be declared locally.