This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How do I extend an abstract inner class  RSS feed

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Guys,
If I have an abstact/non-abstract class and an abstract inner class, How can I extend this inner class?

Does it make any sense in real world to make an inner class abstract??

Thanks!

[ August 23, 2007: Message edited by: Muni K Reddy ]
[ August 23, 2007: Message edited by: Muni K Reddy ]
 
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what "an abstact/non-abstract class" is, but have you tried using an abstract nested class? It works very much like a top-level abstract class.
 
Bartender
Posts: 3320
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Does it make any sense in real world to make an inner class abstract??

Absolutely. If your class requires the use of a number of other classes that are related to each other (ie form a class hierarchy) and those classes are particular to the parent class (ie are ideal candidates for implementation as inner classes) then it is probable that the super class of the inner class hierarchy will be abstract.
 
Muni K Reddy
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by marc weber:
I'm not sure what "an abstact/non-abstract class" is, but have you tried using an abstract nested class? It works very much like a top-level abstract class.



Mark, I meant abstract or a non abstract top level class but specifically having a nested abstract inner class .
  • How do I extend this abstract inner class?
  • Is it of any value if I make the nested inner class abstract?
  •  
    Muni K Reddy
    Ranch Hand
    Posts: 74
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Absolutely. If your class requires the use of a number of other classes that are related to each other (ie form a class hierarchy) and those classes are particular to the parent class (ie are ideal candidates for implementation as inner classes) then it is probable that the super class of the inner class hierarchy will be abstract.



    Tony, I meant marking the nested inner class abstract, not the outer class! Does it make sense?
     
    marc weber
    Sheriff
    Posts: 11343
    Java Mac Safari
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Originally posted by Muni K Reddy:
    ...

  • How do I extend this abstract inner class?
  • Is it of any value if I make the nested inner class abstract?
  • Tony's explanation applies to abstract classes in general, whether they are top-level or nested. It's the same idea, just in the context of an enclosing class.

    As for how to extend an abstract nested class... It's the same as extending a concrete nested class, except that you need to implement any abstract methods (just as you would if you were extending a top-level abstract class).

    The best way to learn about this is to try writing some code.
     
    Muni K Reddy
    Ranch Hand
    Posts: 74
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator


    Tony's explanation applies to abstract classes in general, whether they are top-level or nested. It's the same idea, just in the context of an enclosing class.

    As for how to extend an abstract nested class... It's the same as extending a concrete nested class, except that you need to implement any abstract methods (just as you would if you were extending a top-level abstract class).

    The best way to learn about this is to try writing some code.



    Mark, After a bit of fighting I did this.


    When I had posted the question I tried to do something like this:

    Does this imply that the outer class needs to be extended before any of the inner classes can be extended ?. I guess it does not make sense to directly inherit an inner class.
     
    marc weber
    Sheriff
    Posts: 11343
    Java Mac Safari
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Originally posted by Muni K Reddy:
    ... Does this imply that the outer class needs to be extended before any of the inner classes can be extended ? ...


    Not necessarily, because you can extend a nested class within the same enclosing class. For example...

    Also note that in your code, A1 extends Test, so A1 inherits the nested class TestINNER. Therefore, you can just say "A2 extends TestINNER" instead of "A2 extends Test.TestINNER."

    Here are some other things you can do...
     
    Muni K Reddy
    Ranch Hand
    Posts: 74
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Marc! That clears a few doubts!
    [ August 24, 2007: Message edited by: Muni K Reddy ]
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!