Java OCA OCP Practice Question 2105

Question

determine the behavior of this program:.

public class Main {
    public Main() {
        System.out.println("In Main constructor ");
    }
    public void printType() {
        enum Letter { B, A, C }
    }
}
  • 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. this code will produce a compiler error: enum types must not be local
  • D. this code 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.




PreviousNext

Related