>> >>http://java.sun.com/docs/books/tutorial/java/javaOO/innerclasses.html
>> >>(scroll to the end)
[quoted text clipped - 7 lines]
>Did you replace the ... parts with appropriate "null" returns? If i do
>that, it compiles fine for me.
Yup, just like your example below did.
>Also note that the StackIterator class is not a local class, but an
hmm... but StackIterator is in a method, doesn't that make it a local
class - ie. not a member of the enclosing class?
>inner class of Stack. If it where a local class the code would look
>like this:
Yup, all because of the missing "private" access modifier.
>public class Stack {
> private ArrayList<Object> items;
[quoted text clipped - 21 lines]
> }
>}
Stefan Schulz - 16 Jan 2006 12:10 GMT
> >Also note that the StackIterator class is not a local class, but an
>
> hmm... but StackIterator is in a method, doesn't that make it a local
> class - ie. not a member of the enclosing class?
It seems you are confused about the types of classes. Let me try to
illustrate things a bit further. Paste the following into a file called
Example.java:
public class Example {
/* a public toplevel class */
private class Nested {
/* this is a nested class. It may have any access modifier */
}
public void foo() {
class Local {
/* this is a local class, and may not have any access
* modifiers
*/
}
new Object(){
/* this is an anonymous class, which can not have any access
* modifier (and not even a name)
*/
}
}
}
class AnotherToplevel {
/* this is another toplevel class.
* The only legal modifier is public, but only if the class is
* declared in a file matching its name.
*/
}
Daniel Dyer - 16 Jan 2006 14:00 GMT
>> >Also note that the StackIterator class is not a local class, but an
>>
[quoted text clipped - 4 lines]
> illustrate things a bit further. Paste the following into a file called
> Example.java:
He's not confused, the example is broken, it has a local class with a
private modifier and doesn't compile unless you remove it. You might not
be looking at the same bit he's talking about, it's the very last section
of code, just above "Other Facts about Nested Classes".
Dan.

Signature
Daniel Dyer
http://www.dandyer.co.uk
Stefan Schulz - 16 Jan 2006 14:49 GMT
> He's not confused, the example is broken, it has a local class with a
> private modifier and doesn't compile unless you remove it. You might not
> be looking at the same bit he's talking about, it's the very last section
> of code, just above "Other Facts about Nested Classes".
>
> Dan.
The last paragraph is correct. The example before it, however... my
guess is they meant to put the "StackIterator" class outside the
method. Definitly worth fixing, though.