Inner classes provide a mechanism to accurately model this connection.
Hence, they can implicitly refer to instance variables and methods of the enclosing class.
[1] Local inner classes are often used in Java to define callbacks for GUI code.
Components can then share an object that implements an event handling interface or extends an abstract adapter class, containing the code to be executed when a given event is triggered.
Anonymous inner classes are also used where the event handling code is only used by one component and therefore does not need a named reference.
This avoids a large monolithic actionPerformed(ActionEvent) method with multiple if-else branches to identify the source of the event.