File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Accessing a superclass's method of and instance of outter class from static inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Accessing a superclass Watch "Accessing a superclass New topic
Author

Accessing a superclass's method of and instance of outter class from static inner class

John Landon
Ranch Hand

Joined: Sep 25, 2008
Posts: 227
Hi,
Class A contains static class B that has static methodB. Class A extends class C and inherits its public methodC.
I want to access methodC from methodB. I need to be sure that the instance of Class A that I call methodB from is used in methodB.
How?

Thanks,
John,
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 272

Since the inner class B is static, you can't access any instance methods or fields from its outer class A. This is just like static methods--if a method is static, you can't access instance members either.


SCJP 6 || SCWCD 5
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

It seems to me like class B may need to be non-static; it then gets an automatic reference to its enclosing instance of class A. It can then simply call "methodC". If that would cause name clashes you can use A.this.methodC -- the A.this is the reference to the enclosing instance.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing a superclass's method of and instance of outter class from static inner class
 
Similar Threads
singleton class methods
abstract class inplementing an interface
What is the difference between these methods?
objects and references
synchronization basics