标签:print private name 局部内部类 匿名内部类 style alt class mamicode
public class OutClass { public String name = "十点多"; public class InnerClass { public String name2 = name; } public void show() { InnerClass innerClass = new InnerClass(); System.out.println(innerClass.name2); } }
public class Demo { public static void main(String[] args) { // 访问内部类方法1 OutClass.InnerClass innerClass=new OutClass().new InnerClass(); // 访问内部类方法2 OutClass outClass = new OutClass(); outClass.show(); } }
public class InnerTest { private int num = 10; public void show() { class Inner { public void methord() { System.out.println(num); } } Inner inner = new Inner(); inner.methord(); } }
public class Out { public void methord() { new Inner() { @Override public void show() { System.out.println("匿名内部类"); } }.show(); Inner inner = new Inner() { @Override public void show() { System.out.println("匿名内部类"); } }; inner.show(); } }
标签:print private name 局部内部类 匿名内部类 style alt class mamicode
原文地址:https://www.cnblogs.com/luzhanshi/p/12984405.html