Dear all,
I can't figure out something about anonymous classes.
As far as I have understood by now, anonymous classes represent a specified kind of local (to method) inner classes.
Hence, here is what we can read in Complete
Java 2 Certification Study Guide by Simon Roberts (page 205):
Some classes that you define inside a method do not need a name . A class defined in this way without a name is called an anonymous class
...
This means that anonymous inner classes are unique to method scopes; you cannot have anonymity with a member class
This is OK.
But in dan chisholm's mock exam devoted to anonymous classes, we can find the following example that compiles and runs wells (prints 5):
Can't we say here that the following code:
static A a1 = new A(2) {
{incY();}
public int math() {return x()+y();}
}; defines an anonymous class as a member class of class B? And that the restrictions that are supposed to be applied (actually not qualify them as static) to anonymous inner class do not work any more? That's why a1 is declared as static...
I think I'm wrong about something, but I can't grasp about what exactly...
I would be very grateful for any assistance,
Thanks in advance,
Cyril.
SCJP 1.4, SCWCD, SCBCD, IBM XML, IBM Websphere 285, IBM Websphere 287