Showing posts with label java inner classes. Show all posts
Showing posts with label java inner classes. Show all posts

Monday, December 31, 2012

Inner classes and static nested classes

Terminology
Nested classes are divided into two categories:
  • static. They are simply called static nested classes.
  • non-static. They are called inner classes. 
Ideology
Reasons for using nested classes:
  • It is a way of logically grouping classes that are only used in one place.
  • It increases encapsulation.
  • Nested classes can lead to more readable and maintainable code.

Notes
  1. Access modifiers (private/public/protected) have no effect on inner classes - independant of the modifier, the classes are public.
  2. Inner classes could access members of outer class, no meter of their access modifier.
Usage out of the outer class