| Author |
Inner classes
|
Sricharan Modali
Greenhorn
Joined: Mar 30, 2004
Posts: 19
|
|
If an inner class is like a instance method(it can have modifiers like abstract, private etc) of the enclosing class then - why when an inner class is declared abstract the enclosing class need not be declared abstract? for example class Outer { abstract class Innner { } } complies fine!?
|
 |
Corey McGlone
Ranch Hand
Joined: Dec 20, 2001
Posts: 3271
|
|
An inner class is like a member method in the fact that it can have access modifiers, but it is still very different from a method. If you declare a member method to be abstract, you are saying that the method can not be invoked by an instance of this class. Rather, you need some other class to override that method. Therefore, you have defined an "incomplete" class - one that can not be fully implemented. As such, you are required to mark the class as abstract. However, if you have an abstract class within an enclosing class, there is no problem with the enclosing class. All of its member methods can be invoked properly, etc. I suggest you check out the JLS, §8.1.2 Inner Classes and Enclosing Instances and Getting in Touch with your Inner Class in order to get a better understanding of some of the details pertaining to inner classes. Corey
|
SCJP Tipline, etc.
|
 |
 |
|
|
subject: Inner classes
|
|
|