Multiple choice technology programming languages

Given: 10. class Nav{ 11. public enum Direction { NORTH, SOUTH, EAST, WEST } 12. } 13. public class Sprite{ 14. // insert code here 15. } Which code, inserted at line 14, allows the Sprite class to compile?

  1. Direction d = NORTH;

  2. Nav.Direction d = NORTH;

  3. Direction d = Direction.NORTH;

  4. Nav.Direction d = Nav.Direction.NORTH;

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The Direction enum is nested inside the Nav class, so it must be accessed as Nav.Direction. To use the enum constant NORTH, the full qualified name Nav.Direction.NORTH is required. Options A, B, and C miss either the outer class reference or the enum type.