Enum (Enumerations) opps in Java

Rakesh Jat Feb 05, 2021

In this section i provide a basic introduction on Enumerationsm Keyword Use & understanding.

In this section we talk about a basic introduction to enumerated types. An enumerated types defines a finite set of symbolic names and their values. These symbolic names are usually called enum constant or names constant.

One way to define constant is to declare them as final, static variable in a class (or inheritance) declaration:

 

public class MachineState {

public static final int BUSY =1;

public static final int IDEL =0;

public static final int BLOCKED = -1;

}

 

Such constants are not type-safe, as any int value can be used where we need to use a constant declared in the MachineState class.

 

enum Weekday
{
    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY;
}
public class Test {
    //Driver Method
    public static void main(String arg[])
    {
        Weekday w1= Weekday.WEDNESDAY;
        System.out.println(w1);
    }
    
}

 

Project Files

Loading...
..
This directory is empty.

Comments (0)

Leave a Comment