How to use enum : Enum « Language Basics « Java






How to use enum

  
enum ProgramFlags {
    showErrors(0x01),
    includeFileOutput(0x02),
    useAlternateProcessor(0x04);

    private int bit;

    ProgramFlags(int bitNumber)
    {
        bit = bitNumber;
    }

    public int getBitNumber()
    {
        return(bit);
    }

}

public class EnumBitmapExample {
    public static void main(String args[])
    {
        ProgramFlags flag = ProgramFlags.showErrors;

        System.out.println("Flag selected is: " +
                                flag.ordinal() +
                           " which is " +
                                flag.name());
    }
}

           
         
    
  








Related examples in the same category

1.Enum with switch statement
2.Enum and GenericEnum and Generic
3.Media enumeration constantsMedia enumeration constants
4.Use an enum constructor.
5.Switching on Enum and Adding Methods to an Enum
6.An enumeration of apple varieties. An enumeration of apple varieties.
7.Use the built-in enumeration methods. Use the built-in enumeration methods.
8.Use an enum constructor, instance variable, and method. Use an enum constructor, instance variable, and method.
9.Java enum: Demonstrate ordinal(), compareTo(), and equals().Java enum: Demonstrate ordinal(), compareTo(), and equals().
10.Java enum: Creating an EnumJava enum: Creating an Enum
11.Java enum: EnumMap and Ant statusJava enum: EnumMap and Ant status
12.Java enum: Enum inside class
13.Java enum and varargs
14.This program demonstrates enumerated types
15.Shuffler Enum