Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner classes

 
Sricharan Modali
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic