Practical Use of
Java Inner Classes

Joseph H McIntyre
IBM Personal Software Products


Abstract

Inner classes are a new feature of version 1.1 of the Java language. Inner classes simplify programming constructs for organizing class definitions and event handling code, resulting in easier-to-read and -manage source code. A special type of inner class, the anonymous inner class, can implement an interface directly.

Opportunities abound for using this new technique, and overuse can be tempting. Examples show not only how to use inner classes, but where to use alternative techniques as well.

This paper presents inner classes from two perspectives: 1) using the language to implement inner classes directly and 2) implementing the equivalent code using standard Java syntax (syntax that may be used with older versions of Java or with compilers that do not support inner class syntax).

Boldface will be used to highlight new or changed lines of code when one of the following examples builds on a preceding example.

Download complete paper

This paper is in PDF format and can be viewed and printed with Adobe's Acrobat(TM) Reader. A free copy of the reader is available from Adobe.



JavaTM is a trademark of Sun Microsystems, Inc.

Microsoft, Windows and Windows NT are registered trademarks of Microsoft Corporation.

Other companies, products, and service names may be trademarks or service marks of others.

Copyright    Trademark



  Java Education Java Home  
IBM HomeOrderEmployment