简体   繁体   中英

Is it possible to override only required abstract methods in interface or Abstract classes among n-methods?

是否有可能只覆盖一组抽象方法中的接口中的一些抽象方法?

是的,你可以提供你的课程也是abstract

Is it possible to override only some abstract methods in interface

Yes, but since the resulting class is still not fully concrete , this class has to be declared abstract .

This compiles fine:

interface MyInterface {
    void method1();
    void method2();
}

abstract class MyClass implements MyInterface {
    public void method1() { }
}

(but it won't compile without the abstract modifier).

If you can implement some abstract methods by making the class itself abstract, as its not fully implemented. Ex:

public interface ITest {

    public void add();

    public void sub();
}

is your interface and class is like :

abstract class  IClass implements ITest
{

    @Override
    public void add() {     

    }
}

is possible.

您可以创建一个扩展抽象类但不需要实现其抽象方法的具体类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM