提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
创建内部类的实例
public class ShadowTest { public int x = 0;/* 来 自 时 代 J a v a - nowjava.com*/ class FirstLevel { public int x = 1; void methodInFirstLevel(int x) { System.out.println("x = " + x); System.out.println("this.x = " + this.x); System.out.println("ShadowTest.this.x = " + ShadowTest.this.x); } } public static void main(String... args) { ShadowTest st = new ShadowTest();/**来自 n o w j a v a . c o m**/ ShadowTest.FirstLevel fl = st.new FirstLevel(); fl.methodInFirstLevel(23); } }