Skip to content
Sharp

Modern Java · interview question

How can you add additional information to an enum constant in Java?

Multiple choiceMediumchapter-7-curatedpremiummodern-javaenums
java
enum Day {
    MONDAY("Start of work week"),
    FRIDAY("End of work week");
    private String description;
    Day(String description) {
        this.description = description;
    }
}
Choose one answer
Answer and explanation

Correct answer

A. By defining fields and a constructor within the enum

Why

You can add fields and a constructor to an enum to associate additional data with each constant. This allows you to store extra information directly within the enum constants.

Test yourself on Modern Java

A free test with instant, explained results. No account needed.

Start free test
All Modern Java questions →