This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 4530
    
    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: 38441
    
  23
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Accessing outer class members from instance of inner class