普通内部类的创建写法
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();
}
}