Lecture 05b - InnerClasses
Lecture 05b - InnerClasses
Programming
Inner Classes
Simple Uses of Inner Classes
Inner classes are classes defined within
other classes
The class that includes the inner class is
called the outer class
There is no particular location where the
definition of the inner class (or classes) must
be place within the outer class
Placing it first or last, however, will
guarantee that it is easy to find
Aug 7, 2007 5
Inner and Outer Classes Have Access to Each Other's Private Members
Aug 7, 2007 13
Static Inner Classes
A normal inner class has a connection between its objects
and the outer class object that created the inner class
object
This allows an inner class definition to reference an instance
variable, or invoke a method of the outer class
There are certain situations, however, when an inner class
must be static
If an object of the inner class is created within a static method of
the outer class
If the inner class must have static members
Aug 7, 2007 16
The .class File for an Inner
Class
Compiling any class in Java produces a .class file
named ClassName.class
Compiling a class with one (or more) inner classes causes
both (or more) classes to be compiled, and produces two
(or more) .class files
Such as ClassName.class and
ClassName$InnerClassName.class