import java.awt.*; import java.awt.event.*; public class ButtonHolder { private int m,n; Button b; ButtonHolder() { b = new Button(); addOneListener(); addOneListener(); } void addOneListener() { b.addActionListener( new ActionListener() { int n=0; public void actionPerformed(ActionEvent e) { ++n; ++m; } } ); } // Now, imagine you make three new ButtonHolder()s, // and each ButtonHolder makes two of these anonymous inner classes. // How many n's? How many m's? // Note that the instance of the ActionListeners are not fields // of ButtonHolder; their closure does include fields of ButtonHolder, though. // Also note that other parts of code (e.g. the awt event handler) // has references to the ActionListener, even though ButtonHolder() is not in its scope. }