Enumerated data type

Enumerated data type:

We can use the enumerated type in java using the enum keyword. This keyword can be used similar to the static final constants.

public enum day{Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};

The advantages of using the enumerated types are:

 compile–time type safety.

 we can use the enum keyword in switch statements.

public class workingdays
{
enum days
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
}
public static void main(String args[ ] )
{
for(days d: days.values())
{
weekend(d);
}
}
private static void weekend(days d)
if (d.equals (days.Sunday))
System.out.println(“value=”+d+”is a holiday”);
else
System.out.println(“value=”+d+”R1 is boundary day”)
}
}

Related

Java 618768343266687721

Post a Comment

emo-but-icon

item