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:
- public enum Color { RED, YELLOW, GREEN }
- enum Fruit {
- Banana(Color.RED),
- Apple(Color.YELLOW),
- Kiwi(Color.GREEN);
- private Color color;
- Fruit(Color color) {
- this.color = color;
- }
- }
- class Test {
- public void method() {
- // insert code here
- }
- } 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)- A13% (3)
- B8% (2)
- C75% (18)
- D4% (1)
Community Discussion
No community discussion yet for this question.