ENUM Types
Posted on: July 5, 2010 at 12:00 AM
In this SCJP section ,you will learn about ENUM Types of java

ENUM Types

A Enum type consist of a fixed set of constants. In java, you define an enum type by using the enum keyword. For example, you would specify a months-of-year enum type as:

public enum Year{
 January,February,March,April,May,June,July,August,September,October,November,December
     
}


Example :

package SCJP;

enum Foods {

burger, frenchFries, , Coke,

}

public class EnumExample {

public static void main(String args[])

{

Foods fd;

fd = Foods.burger;

switch(fd) {

case burger:

System.out.println("You have decided to eat burger!");

break;

case frenchFries:

System.out.println("You have decided to eat frenchFries");

break;

case Coke:

System.out.println("You have decided to eat  Coke");

break;

case Dosa:

System.out.println("You have decided to eat  Dosa");

break;

default:

System.out.println("I don't wanna eat any thing.");

break;

}

}

}

Output :

C:\Program Files\Java\jdk1.6.0_18\bin>java EnumExample 

You chose burger!

Download Source Code

See Also : Enum Type

Related Tags for ENUM Types:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.