Inialization of enum Constatnts
enum MyStatus {
PASS(1), FAIL(0); /*Passing values to the enum constants during
creation time.Calls the constructor for assigning values*/
public int status;
private MyStatusint s) {
status = s;
}
}
public class Enum {
public static void main(String[] args) {
int i = MyStatus.PASS.status; /*Accessing value of PASS constant*/
if (i == 1) {
System.out.println("My Status is:SUCCESS");
} else {
System.out.println("My Status is:FAILURE");
}
System.out.println("Enum Constants are:");
for (MyStatus st : MyStatus.values()) { /*To display all constants*/
System.out.println(st);
}
}
}
Output:
My Status is:SUCCESS
Enum Constants are:
PASS
FAIL