Java Enums — Java Technical Interview Questions & Answers

Java Enums

Java Enums

  • enum defines a fixed set of named constants. Safer than int/string flags.
  • Can have fields and methods.
  • Compare with == for enum constants.
  • Write one tiny example for Enums. Compile, print one result, and say the output out loud before you type.
  • Use Enums only when the problem needs it. Don’t force it into every program. Know one beginner trap.
  • Let's take this on the board with one tiny Main class — no extra files. Java Enums — prints MON and true — enums are typed constants. Start from main, go line by line, and stop at each print. That output is the proof for Enums.

Technical Interview Tip: Show Day.MONDAY style usage in one line.

Code Examples for Java Enums

Example

enum Day { MON, TUE, WED }
public class Main {
  public static void main(String[] args) {
    Day d = Day.MON;
    System.out.println(d);
    System.out.println(d == Day.MON);
  }
}

Java Enums — prints MON and true — enums are typed constants.

How to Explain Java Enums to an Interviewer

What is Enums?

Enums is a Java idea you should explain with one small example. Know the keyword / API used for Enums. Type a tiny Main and print one result. For Enums, say the output before you code.

Why do we use Enums in Java?

Makes the program clearer or safer Enums is a Java idea you should explain with one small example.

Write one small example of Enums.

Show syntax Say what prints

What mistake do beginners make with Enums?

Only the name, no example Enums — only memorising the heading. No example, no trap.

Where is Enums used in a real program?

Day-to-day Java code