Flow control

5 respostas
balrog
public class SolarSystem {	

static String[] planets = {Mercury, Venus, Earth, Mars,

Jupiter, Saturn, Uranus, Neptune, Pluto};

public static String travelTo(int position) {

try {

return planets[position] + " exists";

} catch (ArrayIndexOutOfBoundsException abe) {

System.out.print("The boundaries have been exceeded ");

return “”;

} finally {

System.out.print("within our solar system ");

}

}

public static void main(String[] args) {

System.out.println(SolarSystem.travelTo(2));

}

}

qual a saída ?

1 The following is printed, 'Venus exists’
2 The following is printed, 'Earth exists’
3 The following is printed, 'within our solar system Venus exists’
4 The following is printed, 'within our solar system Earth exists’
5 ArrayIndexOutOfBoundsException is thrown

5 Respostas

Ironlynx

4?

balrog

yeah

caiofilipini

A saída é realmente a opção 4, pois o bloco finally é executado antes de o método travelTo() retornar seu valor.

Valeu!

V

Eu achei essa pergunta realmente simples, na prova caem muitas dessas ou questões simples como essa raramente aparecem???

caiofilipini

A questão é simples, mas se vc não prestar atenção, erra fácil… Acho q o objetivo da prova é esse mesmo.

Criado 13 de julho de 2003
Ultima resposta 14 de jul. de 2003
Respostas 5
Participantes 4