第十一次作业

package 第十一次;
class A{
    private B b = null ;
    public void fun() {
        this.b = new B(this);
        this.b.fun() ;
    }
    public void print() {
        System.out.println("Hello World!!!");
    }
};
class B{
    private A a = null;
    public B(A a) {
        this.a = a;
    }
    public void fun() {
        this.a.print();
    }
};
public class Shyi {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new A().fun();
    }

}

public abstract class A {
    private String name;
    public A(String name) {
        this.name=name;
    }
    public String getName() {
        return this.name;
    }
    public abstract void fun();
}
public class B extends A {
    //抽象类不能实例化
    public B(String name) {
        super(name);
    }
    public void fun() {
        System.out.println(super.getName());
    }

}
public class DemoAB {

    public static void main(String[] args) {
        B b =new B("悟空");
        b.fun();
    }
}

 

posted @ 2017-12-04 21:08  徐丶杨  阅读(70)  评论(0编辑  收藏  举报