Home > DeveloperSection > Interviews > What is enum datatype in java

Posted on    July-14-2015 12:58 AM

 Java Java 
Ratings:
 1 Answer(s)
  422  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Points:4035
Posted on    July-14-2015 12:58 AM

Enum keyword is used to represent a fixed number of related values. Since enum constants are implicitly static and final,there values can't be changed once they are created.
public enum Day {
 SUNDAY, MONDAY, TUESDAY, WEDNESDAY,THURSDAY, FRIDAY, SATURDAY 
}
// Uses 
public void weekDay() {
 switch (day) {
 case MONDAY:
 System.out.println("Mondays are bad.");
 break;
 }
}

Don't want to miss updates? Please click the below button!

Follow MindStick