<span style= "font-family:arial, Helvetica, Sans-serif;" ><span style= "FONT-SIZE:18PX;" >package nested_inner_class;</span></span>
<span style= "FONT-SIZE:18PX;" >public class StaticNestedTest3 {public static void main (string[] args) {//Peculiar inner class instantiation method Outer3 Outer3 = new Outer3 (); oute R3. Nested Nested = Outer3.new Nested ();//cannot be created using the following method, only the static nested class//outer3.nested Nested = new outer3.nested () can be created in the following ways; System.out.println (Nested.getvalue ()); System.out.println (Nested.getoutervalue ());}} Class Outer3{private int value = 9;//non-static nested class (also known as Member Inner Class) (NESTED1) can access all (including private) members of the Outer class (Outer)//can understand nested classes as a function of an outer class (Why you can access a member of an external Class) class Nested{int value = 10;/* * Note: * The inner class references the current instance (an instance of the inner class) with this * inner class that references the outer class instance Outer3.class, this differs from the static variable that references the outer class * *///returns the valueint of the Inner class GetValue () {return this.value;} Returns the Valueint Getoutervalue () {//inner class of an external class accessing an external class object in a strange way return Outer3.this.value;}} </span>
Nested classes (nested Class) are classes that are declared inside another class or interface. Nested classes are divided into two types: static inner classes (the static inner Class) and non-static nested classes (Non-static nested Class). Non-static nested classes are also known as Inner classes (inner class)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java Nested classes and internal class examples < three >