It also must be able to access them directly because the Stack 's public interface supports only LIFO access. This is where inner classes come in. Inner classes are used primarily to implement adapter classes like the one shown in this example. If you plan on handling events from the AWT, then you'll want to know about using adapter classes because the event-handling mechanism in the AWT makes extensive use of them. As shown in Using an Inner Class to Implement an Adapter , you can declare a class without a name.
Anonymous classes can make code difficult to read.