In: Computer Science
What are the enumerators for the following enumeration data declaration?
A)enum test {RED, YELLOW, BLUE, BLACK};
B)enum test {RED, YELLOW=4, BLUE, BLACK};
C)enum test {RED=-1, YELLOW,BLUE, BLACK};
D)enum test {RED, YELLOW=6, BLUE, BLACK};
Correct Option: A
Except option A , remaining other options are incorrect declaration.
// In Correct Code
// Screenshot of the code & output
// Code to copy
public class EnumDemo
{
enum test { RED, YELLOW, BLUE, BLACK };
public static void main(String[] args) {
test t=test.RED;
System.out.println(t);
}
}
In correct code
Explanation:
An enum is a special "class" that represents a group of constants (constants are public, static and final (unchangeable - cannot be overridden).
enum class - test enumerator - RED, YELLOW, BLUE, BLACK