A

Admin • 828.43K Points
Coach

Q. What will be the output of the following code?

Code:
enum Day { MONDAY, TUESDAY }
System.out.println(Day.MONDAY.ordinal());
  • (A) 1
  • (B) 0
  • (C) MONDAY
  • (D) Error
  • Correct Answer - Option(B)
  • Views: 16
  • Filed under category Java
  • Hashtags: Java Enums

Explanation by: Admin
`ordinal()` returns the position of the constant in the enum declaration, starting from 0. So MONDAY has ordinal 0.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.