Java OCA OCP Practice Question 161

Question

Which is the first line to trigger a compiler error?

double d1 = 5f;    // p1 
double d2 = 5.0;   // p2 
float f1 = 5f;     // p3 
float f2 = 5.0;    // p4 
  • A. p1
  • B. p2
  • C. p3
  • D. p4


D.

Note

Java uses the suffix f to indicate a number is a float.

Java automatically widens a type, allowing a float to be assigned to either a float or a double.

This makes both lines p1 and p3 compile.

Line p2 does compile without a suffix.

Line p4 does not compile without a suffix and therefore is the answer.




PreviousNext

Related