R
Roedy Green
There are the results of some simple quick experiments.
Have I made any errors?
Inner classes are not permitted to have static methods or fields.
Sorry I don't know why. Nobody I have asked knows why. This is
probably the single most annoying fact about nested classes. If inner
classes need statics, you have to get the outer class to hold them, or
you have to use static nested classes or you have to inherit them.
Oddly, inner classes are permitted to extend classes that do have
static methods and fields.
Nested static classes and inner classes may extend any top level class
in scope.
A nested static class may extend another nested static class of the
same outer class.
An inner class may extend another inner class of the same outer class.
An inner class may extend a nested static class of the same outer
class.
A nested static class may not extend an inner class of the same outer
class.
static nested classes and inner classes may not extend static nested
classes or inner classes of other outer classes, not that you would
ever want to.
There is no such thing as an anonymous static nested class.
There is no such thing as a top level static class.
The complete essay is at http://mindprod.com/nestedclasses.html
Have I made any errors?
Inner classes are not permitted to have static methods or fields.
Sorry I don't know why. Nobody I have asked knows why. This is
probably the single most annoying fact about nested classes. If inner
classes need statics, you have to get the outer class to hold them, or
you have to use static nested classes or you have to inherit them.
Oddly, inner classes are permitted to extend classes that do have
static methods and fields.
Nested static classes and inner classes may extend any top level class
in scope.
A nested static class may extend another nested static class of the
same outer class.
An inner class may extend another inner class of the same outer class.
An inner class may extend a nested static class of the same outer
class.
A nested static class may not extend an inner class of the same outer
class.
static nested classes and inner classes may not extend static nested
classes or inner classes of other outer classes, not that you would
ever want to.
There is no such thing as an anonymous static nested class.
There is no such thing as a top level static class.
The complete essay is at http://mindprod.com/nestedclasses.html