The ordinal() method in an enum returns the zero-based index of the enum constant in the order they are declared. For example, in the StudentResult enum:
public enum StudentResult {
PASS, // ordinal 0
FAIL, // ordinal 1
ABSENT // ordinal 2
}
StudentResult.PASS.ordinal()would return0StudentResult.FAIL.ordinal()would return1StudentResult.ABSENT.ordinal()would return2
This method is useful when you need to determine the position of an enum constant within its declaration order.
