Inner Classes: A Programming Construct
- Author:
- Dung Nguyen, Stephen Wong
- Subject:
- Science and Technology
- Institution Name:
- Connexions
- Collection:
- Connexions
- Grade Level:
- Post-secondary
- Abstract:
In Java, besides having fields and methods, a class can also have other classes as members. Just like fields and methods, a class member of can be static or non-static. A non-static class member is called an inner class. Inner class is a programming construct based on the powerful concept of closure prevalent in the functional programming paradigm. It allows on-the-fly creation of objects, which can communicate transparently with the enclosing object inside of which they come into existence. We illustrate the rationale and use of inner classes via a progression from top level helper classes to named static nested classes, to non-static named classes, and to anonymous inner classes with dynamic on-the-fly instantiation.
- Course Type:
- Learning Module
- Languages:
- English
- Material Type:
- Activities and Labs, Readings
- Media Format:
- Graphics/Photos, Text/HTML, Downloadable docs
- Conditions of Use:
-
Creative Commons Attribution 2.0
Comments