Which of the following lines will compile without warning or error:

  1. float f = 1.3;

  2. byte b = 257;

  3. int i = 10;

  4. boolean b = null;

  5. char c = "a";


Correct Option: C

AI Explanation

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

Option A) float f = 1.3; - This option will compile without error because the value 1.3 is a valid floating-point literal, and it can be assigned to a variable of type float.

Option B) byte b = 257; - This option will not compile because the value 257 is outside the range of the byte data type. The byte data type can only hold values from -128 to 127.

Option C) int i = 10; - This option will compile without error because the value 10 is a valid integer literal, and it can be assigned to a variable of type int.

Option D) boolean b = null; - This option will not compile because the boolean data type can only hold the values true or false. It cannot hold the value null.

Option E) char c = "a"; - This option will not compile because the value "a" is a string literal enclosed in double quotes, and it cannot be assigned to a variable of type char. To assign a character literal, you should enclose it in single quotes ('a').

The correct answer is: C) int i = 10. This option will compile without warning or error because the value 10 is a valid integer literal, and it can be assigned to a variable of type int.

Find more quizzes: