File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner class

 
siraj siddiqui
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we extend inner class ? If yes then how ?
 
jean-gobert de coster
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say, first off, if you could extend them, you would have to see it differently for all 3 types of inner classes.

Regular inner classes, from my experience, can be extended. However you can only extend an inner class from inside its outer class (you may declare its subclass before or after declaring the super class).
Now however you can't extend that inner class from outside its outer class. Think about it: you can't even instantiate a regular inner class without an instance of its outer class.

Regarding anonymous inner classes, it's pretty obvious that you can't extend them... how would you even begin to do this.

And static inner classes, well they're a class of their own. You could extend them however you like by just doing MyClass extends MyOuter.MyInner

[ December 05, 2008: Message edited by: jean-gobert de coster ]
Out of curiosity, I tried this:



Sure enough, it didn't work
[ December 05, 2008: Message edited by: jean-gobert de coster ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A note on terminology, according to the Java Language Specification...

"A nested class is any class whose declaration occurs within the body of another class or interface." (JLS - 8)

"An inner class is a nested class that is not explicitly or implicitly declared static." (JLS - 8.1.3)

So by these definitions, a static nested class is not an inner class.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do things like this...
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic