This is from K&B's
SCJP 5 Chapter 3 Assignments selftest question
public class Knowing {
static final long tooth = 343L;
static long doIt(long tooth) {
System.out.println(++tooth +"");
return ++tooth;
}
public static void main(
String[] args) {
System.out.println(tooth + " ");
final long tooth = 340L;
new Knowing().doIt(tooth);
System.out.println(tooth);
}
}
I would have expected a compiler error because there is a variable
static final long tooth in the class
and final long tooth in the main method. Since this is not shadowing and the class variable is static why isn't there a compiler error?
Thanks in advance,
Meera