非静态内部类的实例化:
public class Outer {
private int size;
public class Inner {
private int counter = 10;
public void doStuff() {
size++;
}
}
public static void main(String args[]) {
Outer outer = new Outer();
Inner inner = outer.new Inner();
inner.doStuff();
System.out.println(outer.size);
System.out.println(inner.counter);
}
}
静态内部类实例化:
public class Outer {
private int size;
public static class Inner {
private int counter = 10;
public void doStuff() {
size++;
}
}
public static void main(String args[]) {
Outer.Inner inner = new Outer.Inner();
inner.doStuff();
System.out.println(outer.size);
System.out.println(inner.counter);
}
}