• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing outer class members from instance of inner class

 
Ranch Hand
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic