Identify the invalid assignments.

  1. float f = \u0038;

  2. long L2 = 2L;

  3. float f = 1.2;

  4. char c = '/u004E';

  5. byte b = 100;


Correct Option: C

AI Explanation

To answer this question, let's go through each option to understand why it is valid or invalid:

Option A) float f = \u0038; - This option is valid. The value \u0038 is the Unicode representation of the character '8', and it can be assigned to a float variable.

Option B) long L2 = 2L; - This option is valid. The 'L' suffix indicates that the literal value 2 is of type long, and it can be assigned to a long variable.

Option C) float f = 1.2; - This option is invalid. The literal value 1.2 is a double, and it cannot be directly assigned to a float variable without an explicit typecast.

Option D) char c = '/u004E'; - This option is invalid. The character literal '/u004E' is incorrect. The correct representation of the Unicode character 'N' should be '\u004E'.

Option E) byte b = 100; - This option is valid. The literal value 100 is within the range of a byte, and it can be assigned to a byte variable.

The correct answer is C. This option is invalid because the literal value 1.2 is a double and cannot be directly assigned to a float variable without an explicit typecast.

Find more quizzes: