Super friendly <br/>code & developer communities

Super friendly
code & developer communities

A place for coders and developers to share, learn and grow together.

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.

P.S. If you have any questions, click here to join our community and feel free to ask any questions.