Java OCA OCP Practice Question 2677

Question

For the following enumeration definition, which one of the following prints the value 2 in the console?

enum Pets { Cat, Dog, Parrot, Chameleon };
a)System.out.print(Pets.Parrot.ordinal());
b)System.out.print(Pets.Parrot);
c)System.out.print(Pets.indexAt("Parrot"));
d)System.out.print(Pets.Parrot.value());
e)System.out.print(Pets.Parrot.getInteger());


a)

Note

Option a) The ordinal method prints the position of the enumeration constant within an enumeration.

Option b) The call print(Pets.

Parrot); prints the string "Parrot" to console.

Options c), d) and e) There are no methods named indexAt(), value(), or getInteger() in Enum.




PreviousNext

Related