• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

What's the purpose of an abstract static class

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic