Answered step by step
Verified Expert Solution
Question
1 Approved Answer
What is the output of the following code? 10 points 3 public class Test { 4 public A2 get() { 5 return new A2(); 6
What is the output of the following code? 10 points 3 public class Test { 4 public A2 get() { 5 return new A2(); 6 } 7 public static void main(String[] args) { 8 11[] arr = new 11[] { (new Test()).get(), (new A2() { public void m2 (int x) { 10 super.m2(x - 1); 11 } 12 }) }; 13 for (11 x : arr) { 14 x.m2(2); 15 } 16 } 17 } 18 interface 11 { 19 void m2(int x); 20 double X = 4; 21 } 22 class A2 implements 11 { 23 A2() {} 24- public void m2 (int x) { 25 try { 26 if (x / X == 0) 27 throw new Exception("There is error"); 28 System.out.println("The value of x is:" + x); 29 1 catch (Fxcention e) { 17 } 18 interface 11 { 19 void m2 (int x); 20 double X = 4; 21 } 22 class A2 implements 11 { 23 A2() {} 24- public void m2 (int x) { 25 try { 26 if (x / X == O) 27 throw new Exception ("There is error"); 28 System.out.println("The value of x is:" + x); 29 } catch (Exception e) { 30 System.out.println(e.getMessage()); 31 } finally { 32 X++; 33 } 34 System.out.println("The incremented value of x is:" + x); 35 } 36 } There is error The incremented value of x is: 3 There is error The incremented value of x is:2 The value of x is: 1 The incremented value of xis: 2 There is error The incremented value of x is: 1
Step 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