Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

What are the different types of inner classes?

The different type of inner classes are as follows:-
Local classes
Anonymous classes
Nested top- level classes
Member 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.

Silpaulin Tarpaulin | Fire Retardant Tarpaulin

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.

Best Teeth Whitening in Delhi | Cosmetic Dental Treatment in Delhi

Static Nested Class
Local Inner Class
Anonymous Inner Class

Type Description
Member Inner Class A class created within class and outside method.
Anonymous Inner Class A class created for implementing interface or extending class. Its name is decided by the java compiler.
Local Inner Class A class created within method.
Static Nested Class A static class created within class.
Nested Interface An interface created within class or interface.

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

Possibly Related Threads...
Thread / Author Replies Views Last Post

Forum Jump:

Users browsing this thread: 1 Guest(s)