Java Code:
1 2 3 4 5 6 7 8 9 10 |
class OuterClass { //Outer class data and members class NestedClass { //Nested or Inner class data and members } } |
Java allows you to declare a class inside a class that is known as nested class.
Nested class are used to logically group classes and interfaces in one place so that it can be more readable and maintainable code.
Advantage of java nested classes
1.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.
2.Nested classes are used to develop more readable and maintainable code because it logically group classes and interfaces in one place only.
3.Code Optimization: It requires less code to write.