🎴 Flashcard Mode

C and Java Programming Fundamentals

Card1 / 20
Mastered0
Review0
QuestionClick to flip

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.)

AnswerClick to flip back
A
import sun.scjp.Color; import static sun.scjp.Color.*;
B
import sun.scjp.Color; import static sun.scjp.Color.GREEN;
💡 Explanation:

To use the enum constant GREEN directly without prefixing it with Color., you must statically import it. import static sun.scjp.Color.*; imports all constants, while import static sun.scjp.Color.GREEN; imports only GREEN. Both require importing the Color class or its static members.

Change Mode