Can you help me understand in a practical example the usage abstract classes vs interfaces?

前端 未结 9 653
孤城傲影
孤城傲影 2020-12-24 04:09

Can you give me an almost overly simplistic understanding of abstract class vs inheritance use and help me so I can truly understand the concept and how to implement? I have

9条回答
  •  情话喂你
    2020-12-24 04:46

    The main difference between an interface and an abstract class is that in the interface you only define what should be the public methods and properties of the object that implements this interface. An abstract class provides some base implementation, but has some "gaps" - abstract methods that the inheritor needs to implement.

    I am not going to do your homework for you, but a hint: the Animal class should NOT contain anything specific for dogs and cats.

提交回复
热议问题