← 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?
- A.Returns SHIPPED, because valueOf ignores case
- B.Returns null
- C.Throws IllegalArgumentException
- 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 →