yas*_*sin 1 java methods abstract implements
我有接口,抽象方法,并且有更多分类,并在下面使用这些引用类型。
public interface InterfaceA {
boolean mehod1();
boolean method2();
boolean newMethod(); //When added new method
}
public abstract class AbstractA implements InterfaceA{
// other common method
}
public Class C extend AbstractA //have to override three method
public Class D extend AbstractA //have to override three method
public Class E extend AbstractA //have to override three method but only should be override old method
public Class F extend AbstractA //have to override three method but only should be override old method
Run Code Online (Sandbox Code Playgroud)
这些类派生了AbstractA类,我只想在接口中使用新方法,而仅实现C和D类,其他则应仅使用旧方法。
应该如何设计?
您可以通过两种方式处理它:
public InterfaceB extends InterfaceA{
// Your new methods definitions here..
}
Run Code Online (Sandbox Code Playgroud)
让C和D类实现InterfaceB。
| 归档时间: |
|
| 查看次数: |
71 次 |
| 最近记录: |