Java OCA OCP Practice Question 2599

Question

What is the result of the following code? (Choose all that apply.)

1:    public enum Letter { 
2:        A(true), B(Boolean.FALSE), C(false), 
3:    D(false), E(false), F(false) /*from   w ww  .ja v a 2  s .  co m*/
4:        boolean printable; 
5:        public Letter(boolean printable) { 
6:           this.printable = printable; 
7:        } 
8:        public boolean printable() { 
9:           return printable; 
10:       } 
11:       public void giveWig() { 
12:          printable = true; 
13:       } } 
  • A. Compiler error on line 2.
  • B. Compiler error on line 3.
  • C. Compiler error on line 5.
  • D. Compiler error on line 8.
  • E. Compiler error on line 12.
  • F. Compiler error on another line.
  • G. The code compiles successfully.


B, C.

Note

Enums are required to have a semicolon after the list of values if there is anything else in the enum.

Don't worry; you won't be expected to track down missing semicolons on the whole exam-only on enum questions.

Enums are not allowed to have a public constructor.




PreviousNext

Related