Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When you extend a class with inner class ?

 
venkatesh rajmendram
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
When a class A extends the Class B, and Class B has
a) Class C as inner class - how does Class A access the methods of Class C ?
b) Class C as method local inner class - how does Class A access the methods of Class C...
Is it the same way as accessing the inner class.....I guess for situation b) it will not be able to access ....?
any knowledge is appreciated..
Thanks
Venkatesh
 
Sandhya Jayaram
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
found some replies in the sun website closely related to your topic.
------------------------------------------------
You need to be accessing a specific instance of the inner class if you are going to use a non-static member of it.
-------------------------------------------------
You cannot simply get an instance of an inner class. You only have the instance of the outer class to work with.
To solve this problem, you can do one of two things:
1) Move your inner class to a separate "outer" class (thus decoupling it from the outer class)
2) If you want to keep it as an inner class, add a "pass-through" method to the outer class which will place the call on the active instance of the inner class.
------------------------------------------------
Re: extending a nested class and parent access
> This is inconsistent with inheritance: you'd think
> that if you extend an inner class, you would inherit
> the abilities and characteristics of that inner class,
> just as you would in other cases of inheritance.
That's a rather facile way of looking at it. Here's another example that contradicts the above stmt: suppose there is a class A in package X that extends another class B in the same package X. Then class A can access any members of class B that are declared to permit package-friendly access. Now if you extend A by class A1 in package Y, then A1 does not have access to those members of class B.
Hope this helps. Hope i haven't confused you even more!!
-sandhya
 
venkatesh rajmendram
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it does not say in case of inheritance what happens to the inner class, will the behavior be inherited by the child class ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic