The following will compile with no errors float abc = 2;
-
True
-
False
In Java and C++, the statement 'float abc = 2;' compiles without errors because the integer literal 2 is implicitly converted (widened) to float 2.0. This is a valid implicit type conversion where a smaller type (int) is assigned to a larger type (float).
The declaration 'float abc = 2;' compiles without error because 2 is an int literal, and Java allows implicit widening conversion from int to float (a smaller/narrower numeric type to a wider one) with no explicit cast required. This is different from narrowing conversions (e.g., assigning a double to a float or int to byte), which do require an explicit cast. Since int-to-float is a safe widening conversion, this statement is True.