标签:
class A{int i;class B{int j;int funB(){int result = A.this.i +this.j;return result;}}}classTest{publicstaticvoid main(String args []){ A a =new A(); A.B b = a.new B(); a.i =2; b.j =3;int result = b.funB();System.out.println(result);}}interface A{publicvoid doSomething();}class B{publicvoid fun(A a){System.out.println("B类的fun函数"); a.doSomething();}}classAImpl implements A{publicvoid doSomething(){System.out.println("doSomething");}}classTest{publicstaticvoid main(String args []){//AImpl al = new AImpl();//A a = al; B b =new B(); b.fun(new A(){//和一个完整实现类的区别在于没有名字//生成了new A()的对象publicvoid doSomething(){System.out.println("匿名内部类");}});}}标签:
原文地址:http://www.cnblogs.com/arroneve/p/5815462.html