| 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: 4167
|
|
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: 32708
|
|
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.
|
 |
 |
|
|
subject: Accessing outer class members from instance of inner class
|
|
|