nerdexam
Oracle

1Z0-851 · Question #107

Given: public class Test { public enum Dogs {collie, harrier}; public static void main(String [] args) { Dogs myDog = Dogs.collie; switch (myDog) { case collie: System.out.print("collie "); case…

The correct answer is D. collie harrier. See the full explanation below for the reasoning.

Question

Given: public class Test { public enum Dogs {collie, harrier}; public static void main(String [] args) { Dogs myDog = Dogs.collie; switch (myDog) { case collie: System.out.print("collie "); case harrier: System.out.print("harrier "); } } } What is the result?

Options

  • Acollie
  • Bharrier
  • CCompilation fails.
  • Dcollie harrier
  • EAn exception is thrown at runtime.

How the community answered

(49 responses)
  • A
    10% (5)
  • B
    6% (3)
  • C
    2% (1)
  • D
    80% (39)
  • E
    2% (1)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice