This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Subclass of inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Subclass of inner class" Watch "Subclass of inner class" New topic
Author

Subclass of inner class

Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
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?
-----------------------------------


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
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".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Subclass of inner class
 
Similar Threads
nested class Danchisholm ques.
an easy js math question
String question
Strings, StringBuffer and equals()
nested class Danchisholm ques.