What are different types of inner classes? Local classes - Local classes are like local variables, specific to a block of code. Their visibility is only within the block of their declaration
Member classes - Member inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables.
Anonymous classes - Anonymous classes have no name, you cannot even provide a constructor. Explain the different types of inner classes. A class within a class is called as inner class. Sometimes it is also known as nested class.
There are 4 types of inner classes.
1. Member Inner Class : A class that is a member ( like methods, attributes ) is called as a member inner class.
2. Local Inner Class: A class which is defined in a block( without name) is known as local inner class.
3. Static Inner Class: A class with static modifier in its definition is known as static inner class. Like other static members, a static inner class member is to be referred by its class name.
4. Anonymous Inner Class: A class that has no name and exactly implements only one interface or extends one abstract class is known as anonymous inner class. AWT and Swings uses inner classes to handle various events.
|