What is the result of the following code?
public class Main { enum Letter { A, B, C } public static void main(String[] args) { System.out.println(Letter.B.ordinal()); } }
B.
The ordinal()
method of an enum returns its corresponding int value.
Like arrays, enums are zero based.
Remember that the index of an enum may change when you recompile the code and should not be used for comparison.