如下:
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;
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;
例如RED(OxffOOOO),GREEN(OxOOffDO),BLUE(OxOOOOff);
但因为你这个枚举是Rainbow内部的,会被编译成静态的static
所以可以这么访问 Rainbow.MyColor.GREEN建议你还是找一些有详细讲述枚举的书来看,应该就会清楚了
B.MyColor treeColor=MyColor GREEN;
F.MyColor purple=MyColor.BLUE+MyColor.RED;这三项都不对