Given the following code:.
public enum Wall { EAST, WEST, NORTH, SOUTH; public static void main (String[] args) { // (1) INSERT LOOP HERE } }
Which loops, when inserted independently at (1), will give the following output:.
Select the three correct answers.
(a) for (Wall d : Wall.values()) { System.out.println(d);//from w w w . j a va2 s . c om } (b) for (Wall d : Wall.values()) { System.out.println(d.name()); } (c) for (String name : Wall.names()) { System.out.println(name); } (d) for (Wall d : java.util.Arrays.asList(Wall.values())) { System.out.println(d); } (e) for (Wall d : java.util.Arrays.asList(Wall.class)) { System.out.println(d); };
(a), (b), and (d)
The static method values()
returns an array with the enum constants for the specified type.
The final method name()
always returns the name of the enum constant.
There is no names()
method for enums in the Java standard library.
The loop in (d) only converts the array of enums to a list, and iterates over this list.
The argument Wall.
class is not an array and, therefore, an illegal argument to the asList()
method.