JAVA CERTIFICATION QUESTION: Inheritance between Generics collections
What happens when compiling and executing the given code?
A. Compilation fails on line 1
B. Compilation fails on line 2
C. ClassCastException is thrown on line 1
D. ClassCastException is thrown on line 2
E. No compile-time or runtime error occurs
Despite the fact that Number is a supertype of Long, the parameterized types List and ArrayList have no relationship.
The assignment on line 1 is therefore between incompatible types, which results in a compile-time error.
(𝘈𝘳𝘳𝘢𝘺𝘓𝘪𝘴𝘵<𝘓𝘰𝘯𝘨>() 𝘥𝘰𝘦𝘴 𝘯𝘰𝘵 𝘪𝘯𝘩𝘦𝘳𝘪𝘵 𝘧𝘳𝘰𝘮 𝘓𝘪𝘴𝘵<𝘕𝘶𝘮𝘣𝘦𝘳> 𝘸𝘩𝘪𝘭𝘦 𝘓𝘰𝘯𝘨 𝘪𝘯𝘩𝘦𝘳𝘪𝘵𝘴 𝘧𝘳𝘰𝘮 𝘕𝘶𝘮𝘣𝘦𝘳).
·Ɐ sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ :uoᴉsnʅɔuoꓛ