Java OCA OCP Practice Question 340

Question

What is the output of the following application?

public class MyClass { 
   public static void main(String[] input) { 
      int myField = 1; 
      myField = myField++ + --myField; /*from  www  .  j  a  v  a2  s .  c  om*/
      if(myField==1) { 
         System.out.print("Plan A"); 
      } else { if(myField==2) System.out.print("Plan B"); 
      } else System.out.print("Plan C"); 
   } 
} 
  • A. Plan A
  • B. Plan B
  • C. Plan C
  • D. None of the above


D.

Note

This code does not compile because it has two else statements as part of a single if-then statement.

Notice that the second if statement is not connected to the last else statement.

Option D, none of the above, is the correct answer.




PreviousNext

Related