File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes What's the purpose of an abstract static class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "What Watch "What New topic
Author

What's the purpose of an abstract static class

Mo Bustany
Greenhorn

Joined: Feb 03, 2003
Posts: 11
I've seen abstract static classes being used an first level inner classes.
1. Is that the only purpose for them? What do you
buy by defining it static other than not having
an inner class per top class instance. And why is
it abstract???
2. Is there a purpose of defining a top level abstract static class?
Thank you
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Mo Bustany:
1. Is that the only purpose for them? What do you
buy by defining it static other than not having
an inner class per top class instance.

A nested ("static inner") class can be instantiated without having an instance of the outer class - in contrast to (normal) inner classes.
And why is it abstract???

For the same reasons you declare top level classes abstract. In fact, a nested class isn't much more than a top level class in the namespace of another class.

2. Is there a purpose of defining a top level abstract static class?

A top level class can't be declared static - it would simply make no sense.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
A nested ("static inner") class can be instantiated without having an instance of the outer class - in contrast to (normal) inner classes.
"Nested class" is a general term which includes inner classes as well as static nested classes (also known as static member classes). The above comment applies to static nested classes but not other nested classes (mostly).
A top level class can't be declared static - it would simply make no sense.
Unfortunately when inner / nested classes were first released in Java, a static nested class was officially known as a "top-level nested class". Which caused no end of confusion, and fortunately when JLS2 came out they got rid of this silly terminology, and top-level class refers only to, well, top-level classes. But if Mo is looking at an out-of-date book, it may refer to a static nested class as "top-levl". Just pretend they said "static nested" instead.


"I'm not back." - Bill Harding, Twister
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Jim Yingst:
A nested ("static inner") class can be instantiated without having an instance of the outer class - in contrast to (normal) inner classes.
"Nested class" is a general term which includes inner classes as well as static nested classes (also known as static member classes). The above comment applies to static nested classes but not other nested classes (mostly).

Oops, then I confused the terms - I thought it was the other way. Thanks for the correction!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What's the purpose of an abstract static class