It programmer development must-all kinds of resources download list, the most complete IT resources in history, personal collection summary.
In two different situations:
An internal class as a member of a class
1. If the inner class is static
The inner class accesses members of the outer class: only members of the external static identity can be accessed.
The inner class method accesses members of the Inner class: Unrestricted.
2. If the inner class is non-static
There is no limit. Only variables defined within the inner class can no longer be modified with static, which defines int i = 2 within the static method, but it is not possible to define static int i = 2 in the methods approach.
Two, the method defines the inner class
The inner class's ability to access the members of an external class depends on whether the method is static and, if it is static, access only to static variables in the outer class, or, if not static, accessible.
The inner class accesses the members defined in the method: Only members of the final identity in the method can be accessed.
Code:
Package edu.text;
public class Outer {
private int int1 = 1;
private static int int2 = 2;
Private final int int3 = 3;
public void Say () {
String str1 = "str1";
Final String str2 = "str2";
Class inner2{
String STR3 = "STR3";
Final String STR4 = "STR4";
void Speakchinese () {
System.out.println (INT1);
System.out.println (Int2);
System.out.println (INT3);
System.out.println (STR1);//error
System.out.println (STR2);
System.out.println (STR3);
System.out.println (STR4);
}
}
}
Class inner1{
private int int4 = 4;
private static int int5 = 5;//error
Private final int int6 = 6;
public void Eat () {
System.out.println (INT1);
System.out.println (Int2);
System.out.println (INT3);
System.out.println (INT4);
System.out.println (INT6);
}
}
}