javaSE-内部类

成员内部类

public class InnerTest {
    class Inner{

    }
}

public class Main {
    public static void main(String[] args) {
        InnerTest innerTest = new InnerTest();
        InnerTest.Inner inner = innerTest.new Inner();
    }
}

静态内部类

public class InnerTest {
    static class Inner{

    }
}

public class Main {
    public static void main(String[] args) {
        InnerTest.Inner inner = new InnerTest.Inner();
    }
}

局部内部类

//和局部变量一样 
public class Main {
    public static void main(String[] args) {
        class Inner{
            public void a()
            {
                System.out.println("a");
            }
        }

        Inner inner = new Inner();
        inner.a();
    }
}

匿名内部类

public abstract class A {
    public abstract void a();
}

public class Main {
    public static void main(String[] args) {
        A a = new A() {
            @Override
            public void a() {

            }
        };
    }
}
posted @ 2022-05-01 00:16  clearHeart99  阅读(20)  评论(0编辑  收藏  举报