Implements vs extends: When to use? What's the difference?

前端 未结 18 791
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 17:03

Please explain in an easy to understand language or a link to some article.

18条回答
  •  佛祖请我去吃肉
    2020-11-22 17:28

    Extends : This is used to get attributes of a parent class into base class and may contain already defined methods that can be overridden in the child class.

    Implements : This is used to implement an interface (parent class with functions signatures only but not their definitions) by defining it in the child class.

    There is one special condition: "What if I want a new Interface to be the child of an existing interface?". In the above condition, the child interface extends the parent interface.

提交回复
热议问题