创建不自动使用超级构造函数的子类

时间:2019-12-18 18:06:57

标签: java inheritance constructor extends

我有几节课:

import java.io.File;
public interface Filter {

    public boolean passes();

}
import java.io.File;

abstract public class PFilter implements Filter {
    String val;
    File file;


    public PFilter(String value, File f){
        val = value;
        file = f;
    }
    @Override
    abstract public boolean passes();

}

最后;

import java.io.File;

public class HFilter extends PFilter {
    public HFilter(String val, File f) {
        super(value, f);
    }

    @Override
    public boolean passes() {
        return file.isHidden();
    }
}

如果可能我无法在super()类中调用HFilter,我想。创建HFilter实例时,一旦输入两个参数,它将自动调用super(),然后就不需要构造函数了吗?

0 个答案:

没有答案