Machine-translated by Google. Questions are authored in English.
Top

Discussion

What ArrayStoreException indicates - which of the following is true?

  • A.An array was created with a negative length.
  • B.A primitive array was assigned to a reference array variable.
  • C.An object of the wrong type was stored through a supertype array reference.
  • D.An array index outside the bounds of the array was written to.

Answer: C

It is the runtime consequence of array covariance: an Object[] variable may really refer to a String[], and storing an Integer into it is caught only when it happens. The generic equivalent cannot arise, because the compiler refuses the assignment that would allow it.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.