The difference between Java implementation interface and inheriting class

Source: Internet
Author: User
A class can inherit only one class, but it is possible to implement multiple interfaces.
The methods inside the interface are abstract methods and must be overridden by all methods. The method of the interface abstraction is overridden, and the inherited class does not have to.

Inheritance in general development in comparison with less, the interface should be a little more., interface is mainly to achieve a loose coupling, easy to maintain, upgrade, inheritance is mainly to improve the reusability of code, a lot of things can be done in the parent class. Subclasses can be used directly, with a word now popular words, the benefits of inheritance is the same as the spelling daddy.
different modifier modifiers (interface), (extends)
In object-oriented programming, you can have more than one inheritance! But the multiple inheritance of the interface is supported, and the inheritance is not supported.
Whereas inheritance has a single root in Java, subclasses inherit only one parent class.
Only global constants, and abstract methods, can be defined in an interface
In inheritance, you can define attribute methods, variables, constants, etc...
When an interface is implemented by a class, the abstract method in the interface must be implemented in the Class!

The difference between Java implementation interface and inheriting class

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.