Given the code
fragment:
int[][] array = {
{
0 },
{
0, 1 },
{
0, 2, 4 },
{
0, 3, 6, 9 },
{
0, 4, 8, 12, 16 } };
System.out.println(array[4][1]);
System.out.println(array[1][4]);
What is the
result?
A.
4 null
4 null
B.
null 4
null 4
C.
An IllegalArgumentException is thrown at run time
An IllegalArgumentException is thrown at run time
D.
4
An ArrayIndexOutOfBoundException is thrown at run time
4
An ArrayIndexOutOfBoundException is thrown at run time
Risposta D
Infatti l'elemento 4° dell array 1 ( { 0, 1 }) non esiste e quindi si scatena un'eccezione.
Nessun commento:
Posta un commento