Java Reference
In-Depth Information
The output from the program is shown here:
In this example, the inner class Inner computes various values from the array nums ,
which is a member of Outer . As explained, an inner class has access to the members of
its enclosing class, so it is perfectly acceptable for Inner to access the nums array directly.
Of course, the opposite is not true. For example, it would not be possible for analyze( ) to
invoke the min( ) method directly, without creating an Inner object.
As mentioned, it is possible to nest a class within a block scope. Doing so simply creates
a localized class that is not known outside its block. The following example adapts the
ShowBits class developed in Try This 5-3 for use as a local class.
Search WWH ::




Custom Search