Java OCA OCP Practice Question 1155

Question

Which statement (exactly one) is true about the following program?

public class Main {
   public static void main(String[] args) {
      double d1 = 1.0;
      double d2 = 0.0;
      byte b = 1;
      d1 = d1 / d2;//from w  ww .  j a v a  2  s  .  co  m
      b = (byte) d1;
      System.out.print(b);
   }
}
  • A. It results in the throwing of an ArithmeticException.
  • B. It results in the throwing of a DivideByZeroException.
  • C. It displays the value 1.5.
  • D. It displays the value -1.


D.

Note

Floating-point operations do not throw exceptions.

This eliminates answers A and B.

It would be impossible for a byte value to be displayed as 1.5.

The only answer left is D.




PreviousNext

Related