Today we will discuss about a very interesting and important topic in Java
Inner Classes
Inner classes let you define one class within another. They provide a type of scoping for your classes since you can make one class a member of another class. Just as classes have member variables and methods, a class can also have member classes.
They come in several flavors, depending on how and where you define the inner class, including a special kind of inner class known as a "top-level nested class" (an inner class marked static), which technically isn't really an inner class.
Types of Inner Classes
Inner Classes
Inner classes let you define one class within another. They provide a type of scoping for your classes since you can make one class a member of another class. Just as classes have member variables and methods, a class can also have member classes.
They come in several flavors, depending on how and where you define the inner class, including a special kind of inner class known as a "top-level nested class" (an inner class marked static), which technically isn't really an inner class.
Types of Inner Classes
- Regular Inner Class (or Simply Inner Class)
- Static
- Method-local
- Anonymous
Advantage of Inner Classes
- Nested classes represent a special type of relationship that is it can access all the members (data members and methods) of outer class including private.
- Nested classes are used to develop more readable and maintainable code because it logically group classes and interfaces in one place only.
- Code Optimization: It requires less code to write.
Hope you like it. Stay tune for more updates on each types.
Happy Learning !!!
0 comments :
Post a Comment