A perfect java blog

Enum (eration) in Java

14 February,2009Narayan Gopal Maharjan

Here you can see the structure of Enum class in java. This class have their own rules and regulation.In this class there is no use of public except in the method value and class access because it doesn’t give any access to client. Some changable user-defined are written in italics.

For enum define , Just use below syntax

1

2

3

//pseudo code

publicenum<em>EnumName</em>{...}

Then after the class defining there is a access of only one attribute that is :

1

2

3

//pseudo code

privatefinal<em>type</em>value;

As there is only one attribute value, which can access some of the listed values in given form:

1

2

3

4

//pseudo code

SymbolicName1(value);

SymbolicName2(value2);

SymbolicNamen(valuen);

For constructor in enum class:

1

2

3

4

//pseudo code

Enumname(datatypev){

value=v;

}

Now for invoking the given symbol or value a method value() must be defined in default.

1

2

//pseudo code

public<em>datatype</em>value(){...};

A simple enum class is given below:
[sourcecode=’java’]
public enum Example {