Java OCA OCP Practice Question 1016

Question

What is wrong with the following if statement?

if(x++) {  
  y = x * z;  
  x /= 2;  
else {  
   y = y * y;  
   ++z;  
}  
  • A. The if condition should use a prefix operator instead of a postfix operator.
  • B. The if condition must be a boolean expression, not a numeric expression.
  • C. There is a missing } before the else.
  • D. There is no break statement to allow control to transfer out of the if statement.


B and C.

Note

The if condition must be a boolean expression.

A } is missing from in front of the else.




PreviousNext

Related