member Inner class
public class User {
private int age=12;
member Inner class
Class in {
public void print () {
System.out.println (age);
}
}
}
public class Test {
public static void Main (string[] args) {
User U=new user ();
User.in i=u.new in ();
I.print ();
}
}
Variable access
public class User {
private int age=12;
member Inner class
Class in {
private int age = 13;
public void print () {
int age = 14;
SYSTEM.OUT.PRINTLN ("local variable:" + age);
System.out.println ("Inner class variable:" + this.age);
SYSTEM.OUT.PRINTLN ("External class variable:" + User.this.age);
}
}
}
Static Inner class
classOut {
private static int age = 12; static class In { public void print() { System.out.println(age); } }}public class Demo { public static void main(String[] args) { Out.In in = new Out.In(); in.print(); }}Method Inner Class
classOut {
private int age = 12; public void Print(final int x) { class In { public void inPrint() { System.out.println(x); System.out.println(age); } } new In().inPrint(); }}public class Demo { public static void main(String[] args) { Out out = new Out(); out.Print(3); }}
In the above code, we move the inner class into the method of the outer class, and then regenerate it into an inner class object in the method of the outer class to invoke the inner class method
If we need to pass in a parameter to a method in the outer class at this point, then the method parameter of the outer classes must use the final definition
As for final, there's no special meaning here, it's just a representation.
Java Internal classes