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.
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
}
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
upvoted 1 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
BelloMio
6 days, 8 hours agoManuTov
8 months agoShaileshRaj
8 months, 1 week agokuuu
1 year, 4 months agoakbiyik
1 year, 6 months agocarloswork
1 year, 7 months agoiSnover
1 year, 8 months agoshivkumarx
1 year, 9 months ago