Wednesday 31 October 2012

What are different types of inner classes? Nested -level classes, Member classes, Local classes, Anonymous classes. Explain them




There are 4 types of inner classes - Member inner class, Local inner class, Static inner class and Anonymous inner class
1. Member inner class – A member of a class(enclosing class).
2. Local inner class – An inner class that is defined within a block.
3. Static inner class – Like static members, this class itself is static.
4. Anonymous inner class – A class without a name and implements exactly only one interface or exactly extends one abstract class.

The enclosing class can not have the accessibility to the inner class. To do so, the outer class must create an object of its nested class except for static inner class. The member classes can access all of its enclosing class’s members, because inner class is like a member of a class.
Anonymous inner class is used when an object creation, one time single method invocation to be done and releasing the object at once. This is particular in event driven programming.
The nested classes are implemented in handling AWT, Swing and Applet programming. An anonymous inner class is invoked when an action event is to be performed.

No comments:

Post a Comment

What is Map Collection?

A map collection refers to a set of maps that are compiled and organized for a specific purpose, such as research, education, or preservatio...