Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available. The Java programming language allows you to define a class within another class. Such a class is called a nested class and is illustrated here:. A nested class is a member of its enclosing class. Non-static nested classes inner classes have access to other members of the enclosing class, even if they are declared private. Static nested classes do not have access to other members of the enclosing class.
Difference between private, public, and protected modifiers in C++
C# Access Modifiers
Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available. To see an inner class in use, first consider an array. In the following example, you create an array, fill it with integer values, and then output only values of even indices of the array in ascending order. The DataStructure. You can use inner classes to implement helper classes such as the one shown in the this example.
The remaining sections explain these modifiers. Access modifiers are keywords used to specify the declared accessibility of types and type members. The four access modifiers are discussed in the table below:. Note that nested types within the same containing body can also access those private members.
C Information Subscribe C Subscribe by email:. Subscribe by RSS. Follow C on Twitter!