What will be the output of the following Java code snippet? [code] Object[] names = new String[3]; names[0] = new Integer(0); [/code]

KellyPoima

New member
What will be the output of the following Java code snippet?
Code:
Object[] names = new String[3];
names[0] = new Integer(0);
A. ArrayIndexOutOfBoundsException
B. ArrayStoreException
C. Compilation Error
D. Code runs successfully
 
Answer: b
Explanation: ArrayIndexOutOfBoundsException comes when code tries to access an invalid index for a given array. ArrayStoreException comes when you have stored an element of type other than the type of array.
 

Tìm kiếm

Back
Top