Thursday, June 3, 2010

Inner classes in java

Inner classes are nested with in classes. Inner classes come in 4 flavors,

1) Static member classes
2) Member classes
3) Local classes
4) Anonymous classes

Let us take a quick look on these,

a static member class is a static member of a class. Like any other static method, a static member class has access to all static methods of the parent, or top-level, class.

Like a static member class, a member class is also defined as a member of a class. Unlike the static variety, the member class is instance specific and has access to any and all methods and members, even the parent's this reference.

Local classes are declared within a block of code and are visible only within that block, just as any other method variable.

an anonymous class is a local class that has no name.

No comments: