Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Accessing outer class members from instance of inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Accessing outer class members from instance of inner class" Watch "Accessing outer class members from instance of inner class" New topic
Author

Accessing outer class members from instance of inner class

Adam Zedan
Ranch Hand

Joined: Jun 10, 2011
Posts: 124

I know i could acess the members of the outer class from the inner class. The question is could i access the members of the outer class from an instance of the inner class
The code i am using is



Don’t look where you fall, but where you slipped
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

The inner class does not have a method named outer_method.

Also. by convention method (and variable) names in Javastart with a lowercase letter and the first letter of each subsequent word is in uppercase.
outer_method --> outerMethod
Innermethod --> innerMethod

Consistent and conventional indenting also makes your code much more readable. I suggest you go through the code conventions for the Java programming language.


luck, db
There are no new questions, but there may be new answers.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
You can access that outer method from anywhere because it has public access. Change it to private access and see what happens. You cannot call the outer method on an instance of the inner class, since it is not a member of the inner class. You can only call the inner method, or a method inherited from Object.

Please use the correct Java™ format for identifiers, using “camel case”, not underscores, and start method names with lower-case letters. Please indent your code correctly; {} should only be on the same line for array initialisers. Please correct the compiler errors you can actually understand before you post code. Line 24, for example.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing outer class members from instance of inner class
 
Similar Threads
Access to "hidden" outer variables
Inner Classes Q
Inner classes
Inner Classes
Doubt in innerclass