Home » Oracle » 1z0-803 » Which approach ensures that the class can be compiled and run?
Given:
Which approach ensures that the class can be compiled and run?
A. Put the throw new Exception() statement in the try block of try – catch
B. Put the doSomethingElse() method in the try block of a try – catch
C. Put the doSomething() method in the try block of a try – catch
D. Put the doSomething() method and the doSomethingElse() method in the try block of a try – catch
Correct Answer: A
Explanation/Reference:
Explanation:
We need to catch the exception in the doSomethingElse() method.
Such as:
private static void doSomeThingElse() {
try {
throw new Exception();}
catch (Exception e)
{}
}
Note: One alternative, but not an option here, is the declare the exception in doSomeThingElse and catch it in the doSomeThing method.
Download Printable PDF. VALID exam to help you PASS.
|
|