What is the result?
A. x = 42
B. x = 43
C. x = 44
D. Compilation fails.
E. The code runs with no output.
Answer:
D is correct, the variable x is only in scope within the try code block, it’s not in scope in
the catch or finally blocks. (For the exam, get used to those horrible closing } } } .)
A, B, C, and E is are incorrect based on the above. (Objective 1.3)
==
class Scoop {
static int thrower() throws Exception { return 42; }
public static void main(String [] args) {
try {
int x = thrower();
} catch (Exception e) {
x++;
} finally {
System.out.println("x = " + ++x);
} } }
No comments:
Post a Comment