nerdexam
Oracle

1Z0-850 · Question #47

Given: 1. public enum Color { RED, YELLOW, GREEN } 2. enum Fruit { 3. Banana(Color.RED), 4. Apple(Color.YELLOW), 5. Kiwi(Color.GREEN); 6. private Color color; 7. Fruit(Color color) { 8. this.color =…

The correct answer is C. Fruit[] fruits = Fruit.values(); E. Fruit f = Fruit.Banana; switch (f) {}. See the full explanation below for the reasoning.

Question

Given:
  1. public enum Color { RED, YELLOW, GREEN }
  2. enum Fruit {
  3. Banana(Color.RED),
  4. Apple(Color.YELLOW),
  5. Kiwi(Color.GREEN);
  6. private Color color;
  7. Fruit(Color color) {
  8. this.color = color;
  9. }
  10. }
  11. class Test {
  12. public void method() {
  13. // insert code here
  14. }
  15. } Which two, inserted independently at line 13, allow the code to compile? (Choose two.)

Options

  • AColor red = Color.values()[0];
  • BFruit f = Banana;
  • CFruit[] fruits = Fruit.values();
  • DFruit f = new Fruit(Color.RED);
  • EFruit f = Fruit.Banana; switch (f) {}

How the community answered

(24 responses)
  • A
    13% (3)
  • B
    8% (2)
  • C
    75% (18)
  • D
    4% (1)

Community Discussion

No community discussion yet for this question.

Full 1Z0-850 Practice