Originally posted by Thomas Paul:
Will this code compile? If it does, what happens when it runs?
Compile but won't run.
Arrays are suppose to be a collection of elements of the
same type. The array in the sample code was initialized to contain String. Although its reference
array was cast as Object[], this is acceptable because the type Object[] is at the top just below Object.
When an element of type Object is stored at element 0, the program throws an exception because its type is different from the initialized type of the elements of the array.