10. Given the code below, if the program crashes at run time then write program
ID: 3856492 • Letter: 1
Question
10. Given the code below, if the program crashes at run time then write program crashes otherwise write what the output is after executing the following main method,
public class Q10 {
public static void Q() {
try { System.out.println("C");
int[] test2 = new int[] { 1, 2, 3 };
System.out.println(test2[5]);
System.out.println("D");
}
catch(ArithmeticException ex) {
System.out.println("E");
}
catch(ArrayIndexOutOfBoundsException ex) {
System.out.println("F");
}
catch(Exception ex) {
System.out.println("G");
}
System.out.println("H");
}
public static void main(String[] args) {
Q();
System.out.println("I");
}
}
Answer:
Explanation / Answer
abswer is it will throw the exception ArrayIndexOutOfBoundsException and print F as it acesses the value from the array out of range
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.