Java OCA OCP Practice Question 449

Question

What is the output of the following application?


public class MyClass { 
        public static void main(String[] vars) { 
           int myField = 10 * (2 + (1 + 2 / 5); 
           int myField2 = myField * 2; 
           System.out.print(myField + myField2 < 10 ? "Too few" : "Too many"); 
        } 
} 
  • A. Too few
  • B. Too many
  • C. The code does not compile.
  • D. The code compiles but throws a division by zero error at runtime.


C.

Note

While the code involves numerous operations, none of that matters for solving this problem.

The key to solving it is to notice that the line that assigns the myField variable has an uneven number of parentheses.

Without balanced parentheses, the code will not compile, making Option C the correct answer.




PreviousNext

Related