Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    What are The Nested Classes in Java?

    Java allows programmers to define a class inside another class. This concept helps in grouping classes logically. Nested classes are those classes that are defined or created within another class. It is to be noted that the lifetime and scope of the nested class remains bounded with the scope of its enclosing class.

    Moreover, it has many advantages, as well. Nesting of classes increases the usefulness of encapsulation. Also, the readability and maintainability of code increase with the use of nesting of classes.

    Furthermore, it has full access to its members, both public as well as private members. Nested classes are also treated as members of its encircled class. It is of two types. These are:

    • static nested class: they are declared using the keyword static
    • inner class: classes those are not declared as static (non-static)

    Nested Class Structure

    class OuterClass
    {
    ....
         class NestedClass
         {
         ....
         }
    }


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.