Java-interface supplement-interface implementation

Source: Internet
Author: User

Java-interface supplement-interface implementation
1. More abstract classes than abstract classes are interfaces)
2. There are only two types of interfaces: constants and public abstract methods. That is, void Tes () is equivalent to public abstract void tes () public void Test ().
3. When defining an interface constant, there is public static final before the constant written or not written: int MAX_SPEED = 120; equivalent to public static final int MAX_SPEED = 120;
4. The significance of interfaces lies in the separation of design and implementation. Interfaces abstract the commonalities of many classes.
5. Why do I need interfaces? What is the difference between an interface and an abstract class?
* Interfaces are "abstract classes" that are more restrictive than "abstract classes" and "abstract. The separation of specifications and specific implementations is fully and professionally achieved.
* Interfaces are standards. They define a group of rules, reflecting the idea of "if you are..., you must be..." in the real world. For example, if you are an angel, you must fly. If you are a bad person, you must bully the good person.
* The essence of interfaces is contract, just like the laws between us. After the preparation, everyone follows the rules.
* The specific requirements of the project are changeable. We must develop the project with the same token, and the "unchanged" here is the "standard". Therefore, all our development projects are interface-oriented programming.
6. Define the interface:
Format:
[Access modifier] interface name [extends parent interface 1, parent interface 2] {


Constant definition // always public static final
Method definition // always public abstract


}
7. sub-classes use implements to implement the specifications in the interface
8. The interface cannot create an instance, but can be used to reference the variable type.
9. If a class implements an interface, all methods of the interface must be implemented, and these methods can only be public.
10. Interfaces support multi-inheritance.
11. You can only use interfaces to describe more abstract relationships. Because inheritance can only be a single inheritance and cannot implement more abstract relationships.

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.