← Quiz: Java Enums: all 10 questions
Quiz: Java Enums · Question 4 of 10
What does this print? (code)
What does this print?
enum Coin {
ONE(1), FIVE(5), TEN(10);
final int value;
Coin(int value) { this.value = value; }
}
public class Main {
public static void main(String[] args) {
int total = 0;
for (Coin c : Coin.values()) total += c.value;
System.out.println(total);
}
}
- A.3
- B.0
- C.1510
- D.16
Answer & explanation
Correct answer: 16
Each constant stores its value: 1 + 5 + 10 = 16.
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 →