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

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

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

18条回答
  •  情话喂你
    2020-11-22 17:16

    Both keywords are used when creating your own new class in the Java language.

    Difference: implements means you are using the elements of a Java Interface in your class. extends means that you are creating a subclass of the base class you are extending. You can only extend one class in your child class, but you can implement as many interfaces as you would like.

    Refer to oracle documentation page on interface for more details.

    This can help to clarify what an interface is, and the conventions around using them.

提交回复
热议问题