If x is an int and y is a double, all of the following are legal except which assignment statement?


If x is an int and y is a double, all of the following are legal except which assignment statement?


1) y = x;

2) x = y;

3) y = (double) x;

4) x = (int) y;

5) all of the above are legal

Answer: b. Explanation: Since x is an int, it cannot accept a double unless the double is cast as an int. There is no explicit cast in the assignment statement in b. In a, a cast is not necessary because a double (y) can accept an int value (x), and in c and d, explicit casts are present making them legal.