1z0-808 Exam QuestionsBrowse all questions from this exam

1z0-808 Exam - Question 219


Which two code fragments cause compilation errors? (Choose two.)

Show Answer
Correct Answer: ABCD

A compilation error occurs in option A because a double value cannot be assigned to a float variable without explicit casting. Similarly, in option C, the assignment of a double value to a Float wrapper class is not allowed directly because of the same reason: double cannot be implicitly cast to float. Options B, D, and E involve correct usage of casting and float literals that do not cause compilation errors.

Discussion

8 comments
Sign in to comment
carlosworkOptions: AC
Oct 28, 2022

Answer is AC. Options that do not compile are A and C. Here is similar variables to test: public static void main(String[] args) { double y1 = 203.22; float fit = y1; // A --- error float fit2 = (float) 1_11.00; // B Float fit3 = 100.00; // C --- error int y2 = 100; float fit4 = (float) y2; // D float fit5 = 100.00F; // E }

akbiyikOptions: AC
Dec 7, 2022

The answer is AC

kuuuOptions: AC
Jan 27, 2023

The answer is AC

ShaileshRajOptions: AC
Oct 5, 2023

These answer will give compilation error as question is asking, other option will give no compilation error

shivkumarxOptions: BD
Sep 13, 2022

Think you wrote the question wrong, A,C,E compile fine and BD do not compile

iSnoverOptions: AC
Oct 10, 2022

The answer is AC, I knew but just in case I tested it and here is the explanation of each one: A -> Wrong, because a float cannot receive a double B -> Correct, how are you doing a cast to float compiles C -> Wrong, a float cannot receive a value of 100.00, it is out of its range D -> Compile, cast to float And -> Compiles too, when you put F at the end inform that it is a floating point number, then compile.

ManuTov
Oct 10, 2023

Another repeated question. its the same as n 105.

BelloMioOptions: AC
Jun 6, 2024

Someone gave wrong explanations. The reason why A and C are wrong is because we cannot implicitly cast double values to float. They need to be explicitly casted, but it is possible.