QuestionQ25

Working with Java Data Types

Given:

Question Image

What is the output?

  • A 0 CLOUDY
  • B 1 SNOWY
  • C 0 SNOWY
  • D 1 RAINY
  • E Compilation fails
Explanation

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".

Community Discussion

No comments yet. Be the first to start the discussion!