JAVA 内部类

public class A {

    int i;

    public A() {
        // TODO Auto-generated constructor stub
    }

    class B {

        int j;

        int add() {
            return i + j;
        }
    }

}
public class Test {

    public Test() {
        // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        A a = new A();
        a.i = 3;

        A.B b = a.new B();
        b.j = 4;

        System.out.println(b.add());
    }

}

运行结果

7
posted @ 2020-09-04 18:04  thomas_blog  阅读(143)  评论(0编辑  收藏  举报