Howdy,
OK, I *think* I can clear this up --
First, we're trying to use the term 'nested' instead of 'inner' (but I'll *never* get out of the habit of saying, "inner"), and it's acceptable to use it when referring to anything other than a static nested class.
There are TWO kinds of nested classes:
1) static (also known as "top level nested class" or even "top-level inner class")
2) not static
Although there are static nested classes on the exam, the exam makes extensive use of type 2 -- non-static nested classes (what we normally think of as "inner" classes). This type comes in multiple flavors:
* Member (defined inside the outer class, but not inside a method)
* Method-local
Within a method, the inner (oops, NESTED
) classes can be defined in:
* the method itself
* as an argument to a method
Within the method itself, the nested class can just be declared like a member nested class (except you can't put an access modifier on the method-local nested class, and it can't use non-final local variables).
OR... it can be an anonymous class, which means you're creating an instance of a type, and all you know is the TYPE -- not the name -- of the class.
These anonymous classes can be defined as arguments to a method, or just somewhere inside the method.
The wierd-looking part is that you can define the anonymous class as either a subclass of the class type you specify, or as an implementation class of the interface type you specify. The compiler figures it out. So it *looks* like you're trying to instantiate an interface, but you're not.
Anyway, they're used EVERYWHERE in the exam, but mostly in the
Thread questions (having nothing to do with threads, but they're just a convenient way to build a new Runnable implementation in a very short space). So even though in the real world you would be much more cautious about using them, they're all over the exam as a way to save space, among other things (those other things include, of course, making it just a teeny bit more challenging
But... as long as you don't get thrown off by looking at them, you'll be just fine.
SO... bottom line:
ANYTHING that could possibly be related to a nested class will be in the exam. So we don't specify "anonymous" in the objectives, but "anonymous" is just one particular flavor of "nested class", so it's included.
Whew! Does that help?
Please ask away if it didn't !
-kathy