Question: 2. Write the output of the following code: (You do not need to rewrite the code). Give reasons for your answer. public class Main
2. Write the output of the following code: (You do not need to rewrite the code). Give reasons for your answer. public class Main { public static void main (String[] args) { int v1 = 4; int v2= -2; try { try { test (v1); return; } } catch (Arithmetic Exception e) { System.out.println("Inner catch: " + e.getMessage()); test (v2); } finally { System.out.println("I don't care about exceptions"); } catch (Exception e) { System.out.println("Outer catch: + e.getMessage()); } } // End of main function static void test(int a) { testException (a); return; [15] static void testException(int a) { if (a < 0) { throw new Number Format Exception ("Negative value not allowed"); } else if (a % 2 == 0) { throw new ArithmeticException("Even integer found"); } else { } System.out.println("Input + a);
Step by Step Solution
3.38 Rating (145 Votes )
There are 3 Steps involved in it
The provided Java code defines a class with a main method which executes test method with two input ... View full answer
Get step-by-step solutions from verified subject matter experts
