• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Subclass of inner class

 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an obscure Java question that I hope one of you can answer:
At the top level, I have defined a subclass of an inner class. From a method in that subclass, is there any way to refer to the outer class object or to the outer class object's variables and methods?
In the code below, the method dostuff() is written identically in Inner and SonOfInner. It shows a variety of ways to access methods and data in the outer class -- but all of them fail for the SonOfInner class. Is there any way to do this at all?
-----------------------------------
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Afaik, there isn't. I think you do have a serious design problem here. Why does SonOfInner need to access Outer.this? Do you have a real world example where you need to do this?
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not a real-world example. I am just starting to learn Java, and noticed that it is possible to declare, at the outer level, a subclass of an inner class.
I'm trying to understand how things work, and doubt that I would ever do this in "real life".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic