what is the advantage of interface over abstract classes?

前端 未结 9 1889
野的像风
野的像风 2021-02-01 05:48

In Java, abstract classes give the ability to define both concrete and abstract methods whereas interfaces only give the ability to implement abstract methods. I believe overrid

9条回答
  •  遥遥无期
    2021-02-01 06:33

    The facts are-

    1. Java doesn't support multiple inheritance
    2. Multiple interfaces can be implemented
    3. Few methods in an abstract class may be implemented

    These facts can be used to tilt the advantage in favor of interfaces or abstract classes.

    If there are more than one behavior that a class must share with other classes, interfaces win. If a method definition has to be shared/ overridden with other classes, abstract classes win.

提交回复
热议问题