Differences between extends and implements

Source: Internet
Author: User
Extends can be understood as fully inheriting the features of the parent class. implements can be understood as adding some additional features to this class.
For example, Animal is a parent class, cat, dog, bird, insect all extends Animal, but cat, dog, bird can also implements such as run, shout interfaces, bird, insect can implements such as fly Interfaces
Extends is an inherited parent class. As long as the class is not declared as final or defined as abstract, it can be inherited. JAVA does not support multiple inheritance, but can be implemented using interfaces, extends can inherit only one class, and implements can implement multiple interfaces.
For example, class A extends B implements C, D, E
Interface defines some methods and is not implemented. implements is required for implementation.

Extend can inherit an interface, but it is still an interface and can be used only after implements.

For class, extends is used to (single) inherit a class, while implements is used to implement an interface ). The interface is introduced to partially provide the multi-inheritance function. In the interface, you only need to declare the method header and leave the method body to the implemented class. These implemented class instances can be treated as interface instances. You can also declare an extends (Multi-inheritance) Relationship between interfaces. Note that one interface can be extends with multiple other interfaces.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.