← 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?
- A.It returns Day.SUN
- B.It returns null
- C.It throws IllegalArgumentException
- 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 →