如何在类层次结构中调用方法?

时间:2011-12-05 14:54:08

标签: java polymorphism subclass superclass class-hierarchy

我有这个从另一个类

扩展的超类
public abstract class AbstractDOEMessageFinderAction extends BasicObjectFinder {

    public Object performBasicSearch() {

        // works fine because getQuery is defined in BasicObjectFinder
        return getQuery(); 
    }

另一个类ISIRFinderActionAbstractDOEMessageDashboardAction

延伸
ISIRFinderAction extends AbstractDOEMessageDashboardAction {

    // My aim is to make sure this method works so that I will make
    // the super class's performBasicSearch() method abstract.

    public Object performBasicSearch() {

        // this one doesnt even compile but it extends AbstractDOEMessageDashboardAction
        // which in turn extends BasicObjectFinder
        return getQuery();

    }

}

我错过了什么吗?为什么getQuery无效。我以为它会在类层次结构中搜索它。

2 个答案:

答案 0 :(得分:3)

第二类扩展AbstractDOEMessageDashboardAction而不是AbstractDOEMessageFinderAction

答案 1 :(得分:0)

AbstractDOEMessageDashboardAction是否也会延伸BasicObjectFinder

(注意,AbstractDOEMessageDashboardActionAbstractDOEMessageFinderAction不同。