Questão Arrays

4 respostas
F

Consider the following program…

class ArrayTest
{
   public static void main(String[] args)
   {
      int ia[][] = { {1, 2}, null };
      for (int i = 0; i < 2; i++)
         for (int j = 0; j < 2; j++)
            System.out.println(ia[i][j]);
   }
}

Which of the following statements are true?

a. It will not compile.
b. It will throw an ArrayIndexOutOfBoundsException at Runtime.
c. It will throw a NullPointerException at Runtime.
d. It will compile and run without throwing any exceptions.
e. None of the above.

Sem compilar einh !!!
Valeu !!!

4 Respostas

W

Achu q é a letra B.

R

Vou de C.

F

Gera NullPointerException … pq vc ta tentando acessar uma area que naum existe …
agora se a linha:

fosse substituida por:

Ai a area existiria … mas com nenhum elemento… entao se vc quiser q acessar algum elemento por qq indice … iria gerar ArrayIndexOutOfBoundsException

S

O array é um objeto, quando foi colocado “null” no parametro vc esta dizendo que aquele objeto é um objeto nulo, por isso gera o mesmo tipo de erro que quando vc tenta acessar um objeto nulo…

o ArrayIndexOutOfBoundsException é gerado quando é tentado acessar uma posição inesistente do array…

[]s Victor…

Criado 3 de abril de 2005
Ultima resposta 5 de abr. de 2005
Respostas 4
Participantes 4