Given the following enum declaration, how many lines contain compilation errors?
package mypkg; enum MyBase {} public enum Color extends MyBase { RED, BLUE, ORANGE, GREEN protected Color() {} }
D.
The program contains three compilation problems.
The enum Color extends the enum MyBase
, but enums cannot extend other enums so the definition is invalid.
The enum value list must end with a semicolon (;) if the enum definition contains anything other than the enum values.
Since it includes a constructor, a semicolon (;) is required after GREEN.
enum constructors must be private, meaning the protected constructor for Color does not compile.
Option D is the correct answer.