Question
Consider the following code snippet:
public class Main {
public Main() {
System.out.println("In Main constructor ");
}
public void printType() {
enum PrinterType { DOTMATRIX, INKJET, LASER }
}
}
- A. This code will compile cleanly without any compiler warnings or errors, and when used, will run without any problems.
- B. This code will compile cleanly without any compiler warnings or errors, and when used, will generate a runtime exception.
- C. It will produce a compiler error: enum types must not be local.
- D. It will give compile-time warnings but not any compiler errors.
C.
Note
An enum can only be defined inside of a top-level class or interface and not within a method.
PreviousNextRelated