You are here

Usage

15 January, 2016 - 09:02
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at http://cnx.org/contents/402b20ad-c01f-45f1-9743-05eadb1f710e@37.6

Nested classes are used mostly to avoid name clash and to promote and enforce information hiding. Examples?

Inner classes are used to create (at run-time) objects that have direct access to the internals of the outer object and perform complex tasks that simple methods cannot do. Most of the time, they are defined anonymously. For examples, "event listeners" for Java GUI components are implemented as inner classes. The dynamic behavior and versatility of these "listeners" cannot be achieved by the addition of a set of fixed methods to a GUI component. We shall study Java event handling soon!

An inner object can be thought as an extension of the outer object.