Why are interfaces preferred to abstract classes?

前端 未结 23 1504
鱼传尺愫
鱼传尺愫 2020-12-02 06:23

I recently attended an interview and they asked me the question \"Why Interfaces are preferred over Abstract classes?\"

I tried giving a few answers like:

23条回答
  •  孤城傲影
    2020-12-02 07:23

    This is the issue of "Multiple Inheritance". We can "extends" not more than one abstarct class at one time through another class but in Interfaces, we can "implement" multiple interfaces in single class. So, though Java doesn't provide multiple inheritance in general but by using interfaces we can incorporate multiplt inheritance property in it.

    Hope this helps!!!

提交回复
热议问题