Answered step by step
Verified Expert Solution
Link Copied!

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.

image text in transcribed

image text in transcribed

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 executed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions