Hi,
I'm having a real problem with these questions. Specifically question 9 in Chapter 3 of the Kathy Sierra/Bert Bates self
test at the end. Here's the code:
public class Knowing {
static final long tooth = 343l;
static long doIt(long tooth) {
System.out.print(++tooth + " ");
return ++tooth;
}
public static void main(
String[] args) {
System.out.print(tooth +" ");
final long tooth = 340l;
new Knowing().doIt(tooth);
System.out.println(tooth);
}
}
"What is the result?
a. 343 340 340
b. 343 340 342
c. 343 341 342
d. 343 341 340
e. 343 341 343
f. Compilation fails.
g. An exception is thrown at runtime."
I thought it was e, but I don't understand why it's D. I understand that the tooth within the main block is a local variable, but I guess I just need additional explanation as to why. Is there a hierarchy of which variables are chosen that I missed? Thanks.