An abstract class in Java need not implement any methods from its implementing interface. Why?

前端 未结 5 1092
星月不相逢
星月不相逢 2021-02-04 14:08

Let\'s look at the following simple code snippet in Java.

interface Sum
{
    abstract public void showSum();
}

interface Mul
{
    abstract public void showMul         


        
5条回答
  •  难免孤独
    2021-02-04 14:47

    Abstract classes behavior resembles interfaces in this case.

    From the Java Tutorial: ...abstract classes are similar to interfaces, except that they provide a partial implementation, leaving it to subclasses to complete the implementation. If an abstract class contains only abstract method declarations, it should be declared as an interface instead

    You don't implement methods in an interface that extends another interface. And you don't HAVE to implement methods in an abstract class that implements an interface.

提交回复
热议问题