aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes abstract static inner classes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "abstract static inner classes?" Watch "abstract static inner classes?" New topic
Author

abstract static inner classes?

Karen Marie
Greenhorn

Joined: Nov 10, 2007
Posts: 23
Is it true that the abstract and static modifiers can only apper together when applied to an inner class?

If so, why would you do that?

If not, in what other case can this occur?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Karen]: Is it true that the abstract and static modifiers can only apper together when applied to an inner class?

They can only appear together on a nested class, yes. A static nested class is by definition not an inner class, despite a large number of people who don't seem to know this.

[Karen]: If so, why would you do that?

Why not? It's not common, but there's nothing wrong with it either. When applied to a class, "static" has nothing at all to do with overriding - so the decision of whether to make a class static is completely independent of the decision to make it abstract. You can decide these separately. Generally, make a nested class static if you don't need any enclosed "this" reference to the outer class, and/or if you want the class to have any static members. Make the class abstract if you've got a partial implementation that can be shared among several subclasses. If both these conditions occur for the same class, great, you can have a static abstract class. If not, then you can't. There's nothing special or magic about this combination - you just need to understand the rules for static nested classes, and the rules for abstract classes.
[ December 09, 2007: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Karen Marie
Greenhorn

Joined: Nov 10, 2007
Posts: 23
That was extremely helpful for solidifying the information I read. Thanks a million.
 
wood burning stoves
 
subject: abstract static inner classes?
 
Similar Threads
protected access modifier
question on abstract
static and abstract inner class
Innner Class
abstract method