InterviewSolution
Saved Bookmarks
| 1. |
When do we throw ArrayStoreException in Java |
|
Answer» If there is an attempt to store the wrong TYPE of object into an ARRAY of objects, then the ArrayStoreException is thrown in Java. This exception is thrown at runtime. A program that demonstrates a try-catch block to HANDLE an ArrayStoreException in Java is given as follows: public class Demo { public static VOID main(String args[]) { try { Object obj[] = new Integer[5]; obj[0] = 7.5; } catch (ArrayStoreException e) { System.out.println("The ArrayStoreException is found: " + e); } } }The OUTPUT of the above program is as follows: The ArrayStoreException is found: java.lang.ArrayStoreException: java.lang.Double |
|