1. What is the output of the following code? public class Test public static voi
ID: 3824722 • Letter: 1
Question
1. What is the output of the following code? public class Test public static void main CString CJ args) try int value 30; if (value 40) throw new Exception ("value is too small"); catch (Exception ex) System.out printlnCex.getMessageO); System. out.printlnC"Continue after the catch block"); 2. Show the output of the following code public class Test public class Test public static void main(String CJ args) f public static void main(String[] args) for (int i 0; i 2; i++) try System.out.print(i for (int i 0; i 2; i++) System. out.print(i try System.out.println(1 0); System. out .printlnC1 0); catch CException ex) catch (Exception ex) (a) (b)Explanation / Answer
1. Since it causes exception, the statement in the catch block will be executed. So, answer is "value is too small".
2.in the first snippet, even though an exception is thrown, we are handling it using catch block . Answer will be
0
1
2
In the second snippet, only one number 0, will be printed, as the next statement causes exception and results in terminatiion of the loop
3. Statement 3 will not be executed, as the exception will force the control to return the catch block
Yes, statement 4 will be executed, even thoough the exception is not caught
Yes, even though an exception is caught, statement 4 will be executed
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.