【发布时间】:2014-06-26 13:07:00
【问题描述】:
所以我有一个名为 COL 的类,它包含以下函数:
public class CatalogueOfLife extends EDITPlatform {
private static final String nomatchfound = "there is nothing";
protected String getNoResultsMessage(){
return COL.nomatchfound;
}
然后是一个名为interface的接口,它具有这个功能:
public interface WSInterface {
public boolean matchfound(String noMatchString);
}
最后是一个名为 platform 的抽象类,它使用以下两个函数:
public abstract class EDITPlatform implements WSInterface{
public boolean matchfound(String noMatchString){
if (noMatchString.contains(getNoResultMessage())){
return true;
}
return false; }
现在我想从主函数调用matchfound 函数。我只能使用 COL 对象,但问题是我需要不止一个类来扩展平台。
【问题讨论】:
-
其实我不明白问题出在哪里...为什么只能使用
COL对象?为什么你需要有几个类扩展Platform?你想做COL col = new Platform();之类的事情,然后就可以做col.matchfound(aString)吗? -
因为我实际上将拥有除 COL 之外的其他类来扩展抽象类。例如,我将有
WAP和COL都扩展platform.. 并且每个都会向platform函数发送不同的nomatchfound字符串.. 我需要从平台中调用该函数main,而不必明确指定调用它的子类。 -
我严重怀疑你的接口被称为
interface,因为这是一个Java保留关键字。请张贴真实的类和接口声明,而不是用英文描述它们;这也告诉我们你的类层次结构是什么样的。 -
接口被称为“WSInterface”..层次结构如下:
COL extends platform//platform implements interface -
你能添加一个主要的问题吗?我没有看到问题,所以我想我不明白你的问题。如果 WAP 和 COL 扩展了 Platform,您可以拥有 Platform 对象的集合并调用 obj.matchFound(input)... 类似于 Platform[] platforms= {new WAP(),new COL()};对于每个(平台:平台){platform.matchFound("some string")}
标签: java inheritance abstract-class