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

前端 未结 18 799
爱一瞬间的悲伤
爱一瞬间的悲伤 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

    I notice you have some C++ questions in your profile. If you understand the concept of multiple-inheritance from C++ (referring to classes that inherit characteristics from more than one other class), Java does not allow this, but it does have keyword interface, which is sort of like a pure virtual class in C++. As mentioned by lots of people, you extend a class (and you can only extend from one), and you implement an interface -- but your class can implement as many interfaces as you like.

    Ie, these keywords and the rules governing their use delineate the possibilities for multiple-inheritance in Java (you can only have one super class, but you can implement multiple interfaces).

提交回复
热议问题