• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on abstract class with Inner class concept

 
Martin Arun Paul Perumala
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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 ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 49472
64
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Pie
Posts: 49472
64
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20559
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use Code Tags says it all
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks a lot ..Now I understand
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic