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)
<span style= "FONT-SIZE:18PX;" >package Nested_inner_class;public class StaticNestedTest2 {public static void main (string[] args) {//Do not require an instance of the You can create an inner class object directly outer2.nested1 nested1 = new outer2.nested1 (); System.out.println (Nested1.getvalue ()); System.out.println (Nested1.getoutervalue ());}} class Outer2{private static int value = 9;//static nested class (NESTED1) can access all (including private) members of the Outer class (Outer)//can understand the nested class as a function of the outer class ( Why can I access members of an external class) static class Nested1{int value = 10;//Returns the valueint of the Inner class GetValue () {return value;} Returns the Valueint Getoutervalue () {return outer2.value;}} for the external class </span>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java Nested classes and internal class examples < two >