Multiple choice technology programming languages

This is legal. float f = 2;

  1. Yes

  2. No

  3. Compile error

  4. Don't know

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Java allows implicit narrowing conversion from int literal to float when the value is within float's range. The integer 2 is automatically converted to 2.0f at compile-time, making this statement perfectly legal.