首页 > 解决方案 > 如何传递祖父母对象来调用父方法

问题描述

Class A {

}

Class B extends A {
    public void aMethod(A a){

    }
}

class C extends B {

    aMethod()          /* What argument should i pass in here? I 
        cannot change class A  and Class B */

}

标签: javainheritance

解决方案


由于 C 和 B 都扩展了 A 类,在这种情况下,您可以传递给aMethodA、B 或 C 类的实例


推荐阅读