Hi, i got this question from SC Exam Lab Simulator, Exam 2 - Question 38
public class Asemble{
public static void main(
String args[]){
try{
go1();
}catch(Exception e){}
finally{
System.out.println("B");
}
}
public static void go1()throws ArrayIndexOutOfBoundsException{go2();}
public static void go2()throws ArithmeticException{go3();}
public static void go3()throws InterruptedException{go4();}
public static void go4()throws NullPointerException{
System.out.println("A");
throw new ArrayIndexOutOfBoundsException();
}
}
Answer: Compilation fails
Explanation:
the method go3() can throw the checked exception InterruptedException
if you want to call to the method go3(), the calling statement should be wrapped inside an appropriate 'try' block, or the calling method should be declared to "throws InterruptedException" or super type of InterruptedException.
But the method go2() attempts to call to the go3() method, without fulfilling above requirement. therefore a compile time error will be generated.
I still can't get the explanation point. Please advice.
Thanks
Regards,
Edmen