🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java Enums: all 10 questions

Quiz: Java Enums · Question 4 of 10

What happens with Day.valueOf("sun") when the constant is declared as SUN?

What happens with Day.valueOf("sun") when the constant is declared as SUN?

  1. A.It returns Day.SUN
  2. B.It returns null
  3. C.It throws IllegalArgumentException
  4. D.It does not compile
Answer & explanation

Correct answer: It throws IllegalArgumentException

valueOf needs the exact name, including case.

Can you get the rest right without peeking?

Take the timed Quiz: Java Enums quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →