What is the result of the following code?
1: public class Main { 2: enum Letter { 3: A, B, C; 4: } 5: public static void main(String[] args) { 6: Letter[] animals = Letter.values(); 7: System.out.println(animals[1]); 8: } 9: }
A.
The code compiles.
An enum may be an inner class.
The values()
method returns an array with the enum values in the order in which they were declared in the code.
Since Java uses 0-based indexes, the answer is A.