Question
Assume MyClass contains a public method, doSomething() , which throw s a variety of exceptions, like ArithmeticException , IndexOutOfBoundsException , etc., each under certain distinct
Assume MyClass contains a public method, doSomething(), which throws a variety of exceptions, like ArithmeticException, IndexOutOfBoundsException, etc., each under certain distinct error conditions, and returns without throwing anything when it decides no error has occurred. We call doSomething() four times in a try/catch block:
MyClass a = new MyClass(); try { a.doSomething(); a.doSomething(); a.doSomething(); a.doSomething(); } catch (ArithmeticException e) { System.out.println(" bad math "); } catch (IndexOutOfBoundsException e) { System.out.println(" bad bounds "); } catch (NumberFormatException e) { System.out.println(" bad format "); } catch (Exception e) { System.out.println(" just bad "); } }
Check the true statements (there will be more than one correct answer).
[Ignore whether spaces or ' ' are displayed - it is the words of println()statements that we are interested in.]
After this block is executed, regardless of the conditions that prevail whendoSomething() is called, at least one of the "bad" messages will be displayed on the screen. |
It is possible that doSomething() will return without error in one or more of these invocations, yet we still have one or more of "bad" messages displayed on the screen after this block. |
It is possible neither "bad math" nor "bad bounds" is displayed on the screen after this block. |
It is possible that both "bad math" and "bad bounds" are displayed on the screen after this block. |
It is possible none of "bad math", "bad bounds", "bad format", or "just bad" is displayed on the screen after this block. ------------------------------------------------ Assume that a class, Deep, has an array reference member private int someArrayRef[]; which will be assigned some dynamically-allocated array using new during object construction (in the constructor). Assume, further, that the clone() for class Deep is very short: public Object clone() throws CloneNotSupportedException { Deep newDeepObj = (Deep)super.clone(); return newDeepObj; } Two Deep objects, deepA and deepB are involved in an assignment statement in the client: deepB = (Deep)deepA.clone(); Check the true statements: (There may be more than one.)
|
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