Trail: Learning the Java Language
Lesson: Classes and Objects
Section: Nested Classes
When to Use Nested Classes, Local Classes, Anonymous Classes, and Lambda Expressions
Home Page > Learning the Java Language > Classes and Objects

When to Use Nested Classes, Local Classes, Anonymous Classes, and Lambda Expressions

As mentioned in the section Nested Classes, nested classes enable you to logically group classes that are only used in one place, increase the use of encapsulation, and create more readable and maintainable code. Local classes, anonymous classes, and lambda expressions also impart these advantages; however, they are intended to be used for more specific situations:


Problems with the examples? Try Compiling and Running the Examples: FAQs.
Complaints? Compliments? Suggestions? Give us your feedback.

Previous page: Method References
Next page: Questions and Exercises: Nested Classes