Which two code fragments cause compilation errors? (Choose two.)
Which two code fragments cause compilation errors? (Choose two.)
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.
These answer will give compilation error as question is asking, other option will give no compilation error
The answer is AC
The answer is 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 }
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.
Another repeated question. its the same as n 105.
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.
Think you wrote the question wrong, A,C,E compile fine and BD do not compile