Use the code below to answer the next 4 questions. public static void main(Strin
ID: 3582623 • Letter: U
Question
Use the code below to answer the next 4 questions.
public static void main(String[] args) {
try {
statement1;
method1();
statement2;
} catch (ExceptionA ex) {
statement3;
} finally {
statement4;
}
statement5;
}
public static void method1() {
try {
statement6;
} catch (ExceptionB ex) {
statement7;
} catch (ExceptionC ex) {
statement8;
} finally {
statement9;
}
statement10;
}
Which statements will execute if no exception is thrown?
Which statements will execute if an exception of type ExceptionB is thrown in the try-block of method1 before statement6?
Which statements will execute if an exception of type ExceptionA is thrown in the try-block of method1 before statement6?
Which statements will execute if an exception of type ExceptionM is thrown in the try-block of method1 before statement6?
Explanation / Answer
1. Which statements will execute if no exception is thrown?
Answer : If exception not thrown then all the statements defined in programe including finally block ,but except statements in catch are excuted in the following order .
statement1
statement6
statement9
statement10
statement2
statement4
statement5
2. Which statements will execute if an exception of type ExceptionB is thrown in the try-block of method1 before statement6?
Answer : The statements befor exception,If exception is thrown then relevant catch block caught that exception and excutes statements in catch ,all finally blocks are executed in following order
statement1
statement7
statement9
statement4
3.Which statements will execute if an exception of type ExceptionA is thrown in the try-block of method1 before statement6?
Answer : The statements befor exception,If exception is thrown then relevant catch block caught that exception and excutes statements in catch ,all finally blocks are executed in following order
statement1
statement9
statement3
statement4
4.Which statements will execute if an exception of type ExceptionM is thrown in the try-block of method1 before statement6?
Answer : The exception m is not handeled in programe .So, all finally blocks are executed in following order.
statement1
statement9
statement4
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.