Blakes 21 Days Chapter 16 Document

Day 16, Using Inner Classes and Closures

Inner Classes

First Program - Listing 16.1

Listing 16.1 - The Full Text of

The Explanation

Figure 16.1 - Using inner classes to collect comic books. - goes here


Anonymous Inner Classes

Second Program

LISTING 16.2 The Full Text of

The Explanation

Figure 16.2 - Stopping a program from closing until its work is done. - goes here




Third Program - Listing 16.3

LISTING 16.3 The Full Text of

Figure 16.3 - Monitoring action events with an anonymous inner class. - goes here


The Explanation

Fourth Program - Listing 16.4

LISTING 16.4 The Full Text of

The Explanation


Q & A

Quiz - Questions

  1. Whatcan an inner class access that a separate helper class could not ?
    1. Anonymous inner classes
    2. private variables of another class
    3. Threads
  2. What makes a Java interface qualified to be called a functional interface ?
    1. The number of methods in that interface
    2. The arrow operator
    3. Any interface can be functional.
  3. What does an adapter class make easier ?
    1. The use of closures
    2. Arranging Swing user interface components
    3. Implementing an event listener


  1. B. An inner class can access the private variables and methods of its enclosing class.
  2. A. An interface that defines only one method is a functional interface.
  3. C. An adapter implements all the methods in an event listener interface so you can subclass the adapter and override only the method or methods that are useful.

Certification Practice

  1. What will be the output of this application ?
    1. true
    2. false
    3. Error
    4. The program will not compile.