For the questions below, use the following skeletal code. public static void mai
ID: 3779070 • Letter: F
Question
For the questions below, use the following skeletal code. public static void main(String[ ] args) { try { ExceptionThrowerCode etc = new ExceptionThrowerCode( ); etc.m1( ); etc.m2( ); } catch (ArithmeticException ae) { ... } } public class ExceptionThrowerCode { ... public void m1( ) { ... } public void m2( ) { try { m3( ); } catch(ArithmeticException ae) {...} catch(NullPointerException npe) {...} } public void m3( ) { try { ... } catch(ArithmeticException ae) {...} } } If an ArithmeticException arises in the try statement in m3 1. it is caught in m3 2. it is caught in main 3. it is caught in m2 4. it is caught in m1 5. it is not caught leading to the program terminating
Explanation / Answer
Answer:1. it is caught in m3
Since we handled ArthimaticException in m3() method by using try catch bocks, if that exception arises, then that can be handled in m3() method itself.
If we use throws instead of try catch block then that exception can be handled/caught in main method.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.