Java OCA OCP Practice Question 2337

Question

Which lines of code, when inserted at //INSERT CODE HERE, will print the following:.

BASKETBALL:CRICKET:TENNIS:SWIMMING: 
enum Sports { 
    TENNIS, CRICKET, BASKETBALL, SWIMMING; 
    public static void main(String args[]) { 
       // INSERT CODE HERE 
    } 
} 
  • a for (Sports val:Sports.values()) System.out.print(val+":");
  • b for (Sports val:Sports.orderedValues()) System.out.print(val+":");
  • c for (Sports val:Sports.naturalValues()) System.out.print(val+":");
  • d for (Sports val:Sports.ascendingValues()) System.out.print(val+":");
  • e None of the above


e

Note

Option (a) is incorrect.

The code in this option will print the natural order of the definition of the enum (the order in which they were defined):.

TENNIS:CRICKET:BASKETBALL:SWIMMING: 

Options (b), (c), and (d) define nonexistent enum methods.

Code in these options won't compile.




PreviousNext

Related