• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt on abstract class with Inner class concept

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below is a simple code using Inner class concept.(outer class is abstract and inner class is concrete class).
I want to inherit class B(inner class) only in class C(specific inheritance)

when I am trying to compile the program the error is "an enclosing instance that contains A.B is required." which means to instantiate the class A ?
But class A is abstract which cannot be instantiated.
please help me


[edit]Add code tags. CR[/edit]
[ December 18, 2008: Message edited by: Campbell Ritchie ]
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can instantiate an abstract class as an anonymous class. Can't remember how to do it, but try new C(){};
Please use the CODE button to maintain indentation; it makes the code easier to read.
And inner classes are hardly a beginner's topic: moving.
 
Martin Arun Paul Perumala
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
could you mind if you please give some examples on using codes in the above program.I will try to use them in the next post.
Thank you.
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean the CODE button? You click the button below the "message" window, then {CODE} {/CODE} appears, only the {} are really [].

Then you write your code (or better use ctrl-c ctrl-v) in the gap between ] and [. Then it maintains indentation.

You can also write the code, highlight it, and push the CODE button; it has more-or-less the same effect. You can see how much better the code looks.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use Code Tags says it all
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe this is a re-post of Your other Thread from a few days ago.

Like I said in the other thread, an Object of the inner class B can only exist in the context of an instance of the outer class A. By extending B in a class that does not provide an instance of A as a context then you will be breaking B's ability to refer to its outer class instance. You can't do that.

Also as noted in the other thread you could get around it by extending the Abstract outer class first, then extend the inner class inside the now concrete version of the outer class:


You can also cheat a bit and implement an anonymous extension of the outer class to hold the inner class:


p.s. You should read This Campfire Story to learn more about inner classes.
[ December 18, 2008: Message edited by: Steve Luke ]
 
Martin Arun Paul Perumala
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot ..Now I understand
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic