Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 219

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

    Correct Answer: A, C

    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
ShaileshRajOptions: AC

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

kuuuOptions: AC

The answer is AC

akbiyikOptions: AC

The answer is AC

carlosworkOptions: AC

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 }

BelloMioOptions: AC

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.

ManuTov

Another repeated question. its the same as n 105.

iSnoverOptions: AC

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.

shivkumarxOptions: BD

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