permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner class" Watch "Inner class" New topic
Author

Inner class

siraj siddiqui
Greenhorn

Joined: Dec 05, 2008
Posts: 11
Can we extend inner class ? If yes then how ?
jean-gobert de coster
Ranch Hand

Joined: Dec 04, 2008
Posts: 49
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

Joined: Aug 31, 2004
Posts: 11343

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.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

You can do things like this...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner class
 
Similar Threads
Private
Inner Classes
Question in K&B Book - protected class
Inner Classes
Passing an object to a method.