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)
the ordinal()
method prints the position of the enumeration constant within an enumeration and hence it prints 2 for this program.
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