The meaning of Java interface __java

Source: Internet
Author: User

Because of the learning of Android, I looked back at Java about inheritance and interface, as well as the transition and downward transformation of the content.

If you are enlightened, understand the meaning of the interface, if there is a problem, please predecessors pointed out.

Interface will appear, the most important reason should be the emergence of the upward transition in Java, because the upward transition, the subclass of some of the parent classes do not exist in the method (or the common method) can not continue to invoke. This is troublesome, we need the methods in the subclass, but what do we do?

The first method of adding subclasses to the parent class. However, this method is actually not necessary in the parent class, and the method function body does not need it. Therefore, abstract methods are used, so that there is the birth of abstract methods. But even so, the problem is not resolved, because it is too troublesome, if there are other subclasses to inherit the parent class, it is inevitable that there will be upward transformation of the time, then, this time to the parent class to add an abstract method. is clearly unreasonable.

Then there is the second method, and the interface is born, which explains why the interface is an abstract method. So there is the interface, the subclass of the method required, but the parent class does not have the method can be directly used to complete the interface, there is no need to modify the method of the parent class, in many people work together to complete a project is also more convenient.

I can also say that interfaces must be written by people writing subclass methods.

(If there is a wrong, but also ask the predecessors to point out ~)


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.