Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need the answer within 15 minutes. 3. Write the output for the following Code Snippet. class CustomException extends Exception { int a, b; public
I need the answer within 15 minutes.
3. Write the output for the following Code Snippet. class CustomException extends Exception { int a, b; public CustomException(int a, int b) { this.a = a; this.b = b; } @Override public String toString() { return "CustomException is invoked on a = " + a + ", b = " + b; a public class Main { private static int func(int a, int b) throws CustomException { if ((a % 2 == 0) && (b $ 2 != 0)) { // a Is even, bis odd throw new CustomException(a, b); } return (a + b); 11 public static void main(String[] args) { int res; try { res = func(2, 2); System.out.println("res = " + res); res = func(3, 3); System.out.println("res + res); res = func(2, 3); System.out.println("res + res); func(3, 2); System.out.println("res + res); } catch (CustomException e) { System.out.println(e.toString()); 11 res Write the output when this code is executedStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started