局部内部类可以使用外部类变量(静态、非静态皆可)、方法局部变量 public class TestStatic { static int aa = 5; StringBuffer str = new StringBuffer("cxc"); public static void main(String[] args) { new TestStatic().func1(); } void func1() { aa+=1; final int b = 7; int c = 18; class Inner { int aaa = aa; int bbb = c; StringBuffer sss = str; } Inner inner = new Inner(); System.out.println("this is static demo:"+inner.aaa); System.out.println("this is static demo:"+inner.bbb); System.out.println("this is static demo:"+inner.sss); } } 变量不可被更新,看图: