Java Enums MCQs with answers
51 questions tagged Java Enums, each with the correct answer and an explanation. Page 1 of 3.
- Which of the following classes is the superclass of all Java enums?
- What will this code do?
- Which of the following can NOT be done in enum?
- Enums are best used when:
- What happens if you call `name()` on a null enum reference?
- Which enum constant syntax allows defining constant-specific behavior?
- Is it possible to override `toString()` in an enum?
- What will this code print?
- Can an enum be abstract?
- What type of method is `values()` in an enum?
- What happens when you try to subclass an enum?
- Which of these is NOT true about enums in Java?
- How is an enum constructor called?
- What kind of fields can enums have?
- What will happen if you use `switch-case` with an enum and forget one constant?
- What is the default return value of the `toString()` method in enums if not overridden?
- Can enum constants be compared using '=='?
- What will this code print?
- What does the `ordinal()` method of an enum return?
- Which of the following is the correct way to iterate over an enum in Java?