I am reviewing the concept of inner classes in java. so far from what I\'ve understood and applied java inner classes has a link or access to the methods and fields of its o
If you find that there is enough code which could be better done by class as class provides us to specify stats and behavior with fields and methods and you don't want this class needs to be used outside of enclosing class. you should use inner class.
Here the inner class is hidden from the outside world. Inner class can access the private member of enclosing class which provides us encapsulation.
Let me give example.. Suppose you want to set the gear to cycle and you have a business rule like there are only up to 6 gears. So you can create Inner Class Cycle which would have a method to set the gear. That method has some validation which are checked before setting gear.like the cycle is running...gear number is less than 6...
best example is event handling code uses inner classes(sometimes anonymous inner classes) to create events and listeners without creating separate Event Object and Event Listener classes for your event..