Java OCA OCP Practice Question 3226

Question

Consider the following code snippet:

if(i == 10.0)
    System.out.println("true");

Which one of the following declarations of the variable i will compile without errors and print true when the program executes?

  • a) int i = 012;
  • b) int i = 10.0f;
  • c) int i = 10L;
  • d) int i = 10.0;


a)

Note

Putting 0 before a number makes that number an octal number.

A decimal equivalent of 012 (in octal) is 10.

If you attempt an implicit conversion from float, long, or double types (as given in options b, c, and d respectively) to an integer, you will a get compiler error.




PreviousNext

Related