/* related posts with thumb nails */

Enumerated Data types:

An enum type is a type whose fields consist of a fixed set of constants. It is something like defining words with constant values. These words are easy to remember and closely associated with their meanings -. Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week. Because they are constants, the names of an enum type's fields are generally written in uppercase letters.

The advantages of using enumerated type are:

· Type Safe

· Efficient

· Informative

· We can use the enum keyword in switch statements.

In the Java programming language, we define an enum type by using the enum keyword. For example, we may specify a days-of-the-week enum type as:

class EnumTest

{

enum Days {

SUNDAY, MONDAY, TUESDAY, WEDNESDAY,

THURSDAY, FRIDAY, SATURDAY

}

public static void main(String as[])

{

for(Days d: Days.values())

System.out.println(d);

}

}

Related Topics:

0 comments:

Post a Comment