nerdexam
Oracle

1Z0-851 · Question #256

Given: public class Rainbow { public enum MyColor { RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff); private final int rgb; MyColor(int rgb) { this.rgb = rgb; } public int getRGB() { return rgb; } }…

The correct answer is B. MyColor treeColor = MyColor.GREEN. See the full explanation below for the reasoning.

Question

Given: public class Rainbow { public enum MyColor { RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff); private final int rgb; MyColor(int rgb) { this.rgb = rgb; } public int getRGB() { return rgb; } }; public static void main(String[] args) { // insert code here } } Which code fragment, inserted at line 19, allows the Rainbow class to compile?

Options

  • AMyColor skyColor = BLUE;
  • BMyColor treeColor = MyColor.GREEN;
  • Cif(RED.getRGB() < BLUE.getRGB()) { }
  • DCompilation fails due to other error(s) in the code.
  • EMyColor purple = new MyColor(0xff00ff);
  • FMyColor purple = MyColor.BLUE + MyColor.RED;

How the community answered

(35 responses)
  • A
    3% (1)
  • B
    77% (27)
  • C
    11% (4)
  • E
    6% (2)
  • F
    3% (1)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice