Given the code fragment:
List
Which statement causes a compile time error?
Given the code fragment:
List
Which statement causes a compile time error?
The statement 'Double d = list.get(0);' causes a compile time error. The get method from the list returns an Integer, and there is no implicit conversion between Integer and Double in Java, leading to a compile-time error. All other options either directly assign the Integer value or use unboxing which is implicitly handled by Java.
Only A not compile. Cannot convert Integer To Double directly, (Objetc integer to Object DOuble). ..But can asign Integer to double (primitive). For unboxing (Integer -> int) and then promotion of type int to double.
cannot cast from Integer to Double, Double.valueOf() is needed
cannot convert from Integer to Double
Integer cannot be converted to Double
A, cannot cast from Integer to Double
A is correct Answer
Answer is Option A