Use the following code for the next three questions. public static void main(Str
ID: 3918198 • Letter: U
Question
Use the following code for the next three questions.
public static void main(String[ ] args) {
try {
method1();
method2();
} catch (ArithmeticException ex) {
…
}
}
public static void method1() {
…
}
public static void method2() {
try {
method3();
} catch(ArithmeticException ae) {
…
} catch(NullPointerException npe) {
…
}
}
public static void method3() {
try {
…
} catch(ArithmeticException ae) {
…
}
}
1.
If an ArithmeticException is thrown in the try block in method3, what will happen?
c. it is caught in method1
e. it is caught in method3
2.
If an NullPointerException is thrown in the try block in method3, what will happen?
e. it is caught in method2
3.
If an NullPointerException is thrown in method1, what will happen?
a. it is caught in method2Explanation / Answer
1) e. it is caught in method3 2) e. it is caught in method2 3) a. it is not caught, leading the program to terminate