Java Nested class is defined when a class is present/define within another class. The scope of the nested class is defined within the curly bracket. In java, it is possible to define the class within another class; such classes are known as nested classes.

Nested class In Java

Nested Class enables you to logically group classes that are only used in one place; thus, it increases the use of  encapsulation and creates a more readable and maintainable code.

#Features of nested class

  1. The nested class can access the member of the upper class, but the upper class cannot access the member of the nested class in java.
  2. A class is also called as a member of the enclosing class.
  3. We can declare a nested class as private, public, protected, or default.

#Syntax

See the following syntax.

class outer {
  // statements of outer class
  class inner {
    // statements of inner class
  }
} // outer close

#java nested class #ava #nested classes

Nested class In Java Example | Java Nested Class Tutorial
2.75 GEEK