• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Use of non-static or Inner classes

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Was going through a documentation on Inner classes.It was mentioned that one of the advantage of using Inner classes is that we can use them to access private member of the enclosing class.I agree that the ability of an inner class to access its enclosing class private member is an added advantage but in no way its seems to be the sole reason for using an Inner class.As always we have the option of using the public method for accessing that private field.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Subhendu Dash wrote:Was going through a documentation on Inner classes.It was mentioned that one of the advantage of using Inner classes is that we can use them to access private member of the enclosing class.I agree that the ability of an inner class to access its enclosing class private member is an added advantage but in no way its seems to be the sole reason for using an Inner class.As always we have the option of using the public method for accessing that private field.



Yes, but sometimes the design calls for not exposing those class internals to the general public.

Additionally, nested classes provide a way to keep closely coupled code physically close together, and save you from having another whole top-level class in a separate file for what is typically just a few lines of code.

Finally, as a somewhat more general picture of the access to private data, anonymous inner classes can be viewed as a first-order approximation to a closure. They combine a task to be executed with the context it needs to do its job.
reply
    Bookmark Topic Watch Topic
  • New Topic