Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing outer class members from instance of inner class

 
Adam Zedan
Ranch Hand
Posts: 124
C++ Fedora Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47216
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic