Inner classes in Java and, to a lesser extent, nested classes in C++ and C#
are allowed to access the data areas in the surrounding class.
class AcontainerClass {
...
// return an enumerator
public Enumeration elements()
{ return new MyEnumeration(); }
...
// inner class is allowed to see
// all aspects of surrounding class
private class MyEnumeration implements Enumeration {
...
public boolean hasMoreElements () { ... }
public Object nextElement() { ... }
}
}
Uses a lot for event listeners in Java, among other things.