内部类
作者:互联网
普通内部类的创建写法
public class TestInnerClass{ class InnerClass{ private String name; public void show(){ System.out.println("show"); } } public static void main(String[] args){ InnerClass InnerClass = new StaticClass().new InnerClass(); } }
静态内部类的创建写法
public class TestInnerClass{ static class InnerClass{ private String name; public void show(){ System.out.println("show"); } } public static void main(String[] args){ InnerClass InnerClass = new StaticClass.InnerClass(); } }
方法内部类的写法,需要在方法内new这个内部类
public class MethodInnerClass{ public void show(){ System.out.println("show"); class InnerClass{ private String name; public void show(){ System.out.println("test"); } } new InnerClass().test(); } public static void main(String[] args){ MethodInnerClass methodInnerClass = new MethodInnerClass(); methodInnerClass.show(); } }
?????
标签:InnerClass,内部,show,void,class,new,public 来源: https://www.cnblogs.com/YC-L/p/14207041.html