1.

Why the first one choose B and second one choose E, can you explain me more about this question?

15. Given the following class definition: public class MyException extends Exception { private int errorCode; public MyExcept
15. Given the class definition: public class Jump extends Exception private int n public void Jumpint k)n= k; public int getN

2. How to solve this question?

20. [2 marks] We are given the definitions of two classes: Copoy public class ClassA public int a public class ClassB { publi 15. Given the following class definition: public class MyException extends Exception { private int errorCode; public MyException (int k) { errorCode k; } public getErrorCode () return errorCode; } After executing the following code: int i 0 try i 1; throw new MyException (i) i2; )catch MyException ie.getErrorCode (); )catchException e e ) i-3; The variable i will have the value: a) 0, because the try block will never be executed b) 1, because the MyException object thrown matches the first catch clause c) 2, because after the catch clauses are executed, the control flow goes back to the statement after the throw statement. d) 3, because the MyException object is also an Exception object, and therefore the second catch clause is also matched. e) None of the above Page 6 of 12 15. Given the class definition: public class Jump extends Exception private int n public void Jumpint k)n= k; public int getN return n E then after executing the following code int k-0 try k 1 throw new Jump (k) k 2 catch Exception e k 3; the variable k will have the value: a) 0, because the try block will never be executed. b) 1, because the Jump object thrown does not match the catch clause, and therefore the flow of control leaves the try block entirely. c) 1, because the class Jump does not contain Exception as part of its name, and therefore cannot be used as an exception. d) 2, because the Jump object thrown does not match the catch clause, and therefore the throw statement has no effect. e) 3, because Jump is a subclass of Exception, and therefore the catch clause matches 20. [2 marks] We are given the definitions of two classes: Copoy public class ClassA public int a public class ClassB { public static void ResetAl (ClassA obj){ obj new Clas sA (); public static void ResetA2 (ClassA obj) { obj.a-0; After running the following program: public class DemoProgram public static void main (String [ ] args) { new ClassA (); new ClassA () ClassA myObj1 ClassA myobj2 myObj1.a-2; myObj2.a-2 ClassB. Rese tA1 (myObj1) ; ClassB.ResetA2 (myObj2) What are the values of myObj1.a and myObj2.a, respectively? 2



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *