Java OCA OCP Practice Question 1688

Question

Given the following code:.

package mypkg;//  ww w.  j  a va 2s.  co m
enum Command {
  C1, C2, C3;
 }

package p2;
// (1) INSERT IMPORT STATEMENT(S) HERE
public class Main {
  public static void main(String[] args) {
    for(Command sign : Command.values()) {
       System.out.println(sign);
    }
  }
}

Which import statement(s), when inserted at (1), will result in a program that prints the constants of the enum type Command, when compiled and run?.

Select the one correct answer.

(a) import static mypkg.Command.*;
(b) import mypkg.Command;
(c) import mypkg.*;
(d) import mypkg.Command;
    import static mypkg.Command.*;
(e) import mypkg.*;
    import static mypkg.*;
(f) None of the above.


(f)

Note

The enum type Command is not visible outside the package mypkg.

If it were, (b), (c) and (d) would work.

No static import is really necessary, since the constants of the enum type Command are not used in the package p2.




PreviousNext

Related