如下:
11. public class Rainbow{
12.   public enum MyColor{
13.  RED(OxffOOOO),GREEN(OxOOffDO),BLUE(OxOOOOff);
14.   private final int rgb;
15.  MyColor(int rgb){this.rgb=rgb;}
16.  public int getRGB(){return rgb;}
17. };
18. public static void main(String[] args){
19.//insert code here
}}which code fragment,inserted at line 19.allows the Rainbow class to complie?
A.MyColor skyColor=BLUE;
B.MyColor treeColor=MyColor GREEN;
D.Compilation fails due to other error(s) in the code;
F.MyColor purple=MyColor.BLUE+MyColor.RED;

解决方案 »

  1.   

    B.MyColor treeColor=MyColor.GREEN;
      

  2.   

    我是这么理解的,把它看成一种特殊的类,只不过他的实例都是在里面定义实例化的
    例如RED(OxffOOOO),GREEN(OxOOffDO),BLUE(OxOOOOff);
      

  3.   

    但是枚举的一般是这样写的嘛:Rainbow.MyColor.GREEN
      

  4.   

    一般是这样子写的:MyColor.GREEN
    但因为你这个枚举是Rainbow内部的,会被编译成静态的static
    所以可以这么访问 Rainbow.MyColor.GREEN建议你还是找一些有详细讲述枚举的书来看,应该就会清楚了
      

  5.   

    A.MyColor skyColor=BLUE;
    B.MyColor treeColor=MyColor GREEN;
    F.MyColor purple=MyColor.BLUE+MyColor.RED;这三项都不对