🎙 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 3 of 10

What does Status.valueOf("shipped") do if the constant is named SHIPPED?

What does Status.valueOf("shipped") do if the constant is named SHIPPED?

  1. A.Returns SHIPPED, because valueOf ignores case
  2. B.Returns null
  3. C.Throws IllegalArgumentException
  4. D.Does not compile
Answer & explanation

Correct answer: Throws IllegalArgumentException

valueOf needs the exact name. Different case means no match, which throws IllegalArgumentException.

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 →