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