Java OCA OCP Practice Question 224

Question

Given:

public class Main {
  public static void main(String[] args) {
    String o = "-";
    String[] sa = new String[4];
    for(int i = 0; i < args.length; i++)
      sa[i] = args[i];/*from   w w w. ja v  a2  s .c o  m*/
    for(String n: sa) {
      switch(n.toLowerCase()) {
        case "yellow": o += "y";
        case "red":    o += "r";
        case "green":  o += "g";
      }
    }
    System.out.print(o);
  }
}

And given the command-line invocation:

Java Main RED Green YeLLow

Which are true? (Choose all that apply.)

A.   The string rgy will appear somewhere in the output
B.   The string rgg will appear somewhere in the output
C.   The string gyr will appear somewhere in the output
D.   Compilation fails
E.   An exception is thrown at runtime


E is correct.

Note

The sa[] array receives only three arguments from the command line, so on the last iteration through sa[], a NullPointerException is thrown.




PreviousNext

Related