Java OCA OCP Practice Question 1794

Question

What will be the result of compiling and running the following program?.

public class Main {
   public static void main(String[] args) {
      for (Character c = 'A'; c < 'F'; c++)
         switch (c) {
         default:
            System.out.print((char) ('a' + c - 'A'));
            break;
         case 'B':
            System.out.print(c);/*from   w  ww  .j av  a  2s .  co m*/
            break;
         case 68:
            System.out.print(c); // 68 == 'D'
         }
   }
}

Select the one correct answer.

  • (a) The code will fail to compile because of errors in the for loop header.
  • (b) The code will fail to compile because of errors in the switch statement.
  • (c) The code will compile, but throws a NullPointerException.
  • (d) The code will compile and print: aBcDe


(d)

Note

There are no problems with automatic unboxing/boxing of the Character variable c in the various contexts where it is used in the program.




PreviousNext

Related