简单的小问题。。关于静态导入的。。
Given:
1. package sun.scjp;
2. public enum Color { RED, GREEN, BLUE }
1. package sun.beta;
2. // insert code here
3. public class Beta {
4. Color g = GREEN;
5. public static void main( String[] argv)
6. { System.out.println( GREEN); }
7. }
The class Beta and the enum Color are in different packages.
Which two code fragments, inserted individually at line 2 of the Beta
declaration, will allow this code to compile? (Choose two.)
A. import sun.scjp.Color.*;
B. import static sun.scjp.Color.*;
C. import sun.scjp.Color; import static sun.scjp.Color.*;
D. import sun.scjp.*; import static sun.scjp.Color.*;
E. import sun.scjp.Color; import static sun.scjp.Color.GREEN;
答案CE
为什么ABD不可以呢?
希望大家解释下,谢谢。。
[解决办法]
在包1中实例化了COLOR类对象,所以要引入对象
而在包二中没有实例化GREEN对象就用啦,所以要用STATIC来引入对象
应该如此,具体不知!