Given:
What is the output?
Enum ordinals are zero-based, so SUNNY.ordinal() is 0. valueOf("CLOUDY") returns the CLOUDY enum constant, and printing it calls the enum's overridden toString() method, which returns "SNOWY".
SUNNY.ordinal()
0
valueOf("CLOUDY")
CLOUDY
toString()
"SNOWY"
Community Discussion