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

  1. float f=1.3;

  2. char c="a";

  3. int i=10;

  4. boolean b=null;


Correct Option: C

AI Explanation

To answer this question, we need to understand the data types and their allowed values in Java.

Let's go through each option to understand why it is correct or incorrect:

Option A) float f=1.3; - This option is incorrect because the value 1.3 is a double literal, and it cannot be directly assigned to a float variable without a typecasting. To fix this, you can either change the data type of the variable to double or use a typecasting operator, as shown below: float f = (float) 1.3; or float f = 1.3f;

Option B) char c="a"; - This option is incorrect because the value "a" is a string literal, and it cannot be directly assigned to a char variable. To fix this, you need to use single quotes to represent a char value, as shown below: char c = 'a';

Option C) int i=10; - This option is correct because the value 10 is an integer literal, and it can be directly assigned to an int variable without any issues.

Option D) boolean b=null; - This option is incorrect because the value null cannot be assigned to a boolean variable. Boolean variables can only have two values: true or false.

The correct answer is option C. This option is correct because the value 10 is an integer literal, and it can be directly assigned to an int variable without any issues.

Find more quizzes: