Following code will result in: int a = 3.5;

  1. Compilation error

  2. Runtime error

  3. a being 3.5

  4. a being 3.


Correct Option: A
Explanation:

To solve this question, the user needs to have an understanding of variable types and type casting in programming.

Explanation for each option:

A. Compilation error: This option is correct. In many programming languages, including Java, assigning a floating-point value (such as 3.5) to an integer variable (such as int a) will result in a compilation error. This is because the two types are not compatible, and an explicit type casting is required.

B. Runtime error: This option is incorrect. Runtime errors occur when a program is executed and encounters an error, but in this case, the error would be caught by the compiler during the compilation phase.

C. a being 3.5: This option is incorrect. As mentioned earlier, assigning a floating-point value to an integer variable will result in a compilation error. The value 3.5 cannot be stored in an int variable.

D. a being 3: This option is incorrect. Since the value 3.5 cannot be stored in an int variable, the value of a will not be 3. The code will not compile, so no value will be assigned to a.

Therefore, the correct answer is:

A. Compilation error

Find more quizzes: