Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
enum class Light { RED, YELLOW, GREEN }
fun main() {
println(Light.GREEN.ordinal)
println(Light.entries.size)
}2 3
- Expecting
3 3: countingordinalfrom 1. Positions start at 0, soREDis 0,YELLOWis 1 andGREENis 2. - Expecting
GREEN 3: confusingordinalwithname.namegives the textGREEN;ordinalgives its position, a number.
- What does
println(Light.entries)print? - How would you print the name of the value at position 1?