Java Programming | Using Enumeration


This is a tutorial for enumeration in java. The Enumeration is a set of constants. Its very easy. So Lets See it…

Program for Enumeration in Java.

// declare enum
enum no
    int n; //integer varible
    no(int o)
    n = o;
    //get value
    int getvalue()
      return n;
// the name of our class its public
public class EnumExample {
    //void main
        public static void main (String[] args)
            //print the value of constants
            System.out.println("One is ";
            System.out.println("Two is "+no.two.getvalue());
            System.out.println("Three is "+no.three.getvalue());


One is 1
Two is 2
Three is 3

How does it work

No need to input, directly prints the constants.

Extending it

The program can be extended. This is a basic concept of java programming and has lots of applications.


  1. Declare the enum.
  2. Declare the class as public
  3. Add the void main function
  4. Add system.out.println() function to print the constants.

At the end.

You learnt creating the Java program for Using enumeration. So now enjoy the program.

Please comment on the post and share it.

Join India's Largest Code Learning Community on Get it on Google Play
Sharing options: