The implements usage of JAVA learning __java

Source: Internet
Author: User

Mplements is also a keyword that implements inheritance relationships between parent classes and subclasses, such as Class A inheriting class B written as Class A implements b{}.

This is Baidu encyclopedia on the Interpretation:

Implements is a class that implements an interface keyword that is used to implement an abstract method defined in an interface. For example: People is an interface, he has say this method. public Interface People () {public say ();} However, the interface has no method body. The method body can only be implemented through a specific class. Such as Chinese this class, the implementation of the People interface. Public class Chinese implements people{public say () {System.out.println ("hello.") ");}}

Different from the extends

Extends, you can implement the parent class, or you can invoke the parent class to initialize This.parent (). The variables or functions defined by the parent class are overwritten. The benefit is that the architect defines the interface so that the engineer can implement it. The overall project development efficiency and development costs are greatly reduced.

Implements, implements the parent class, which cannot overwrite the parent class's methods or variables. Even if the subclass defines the same variable or function as the parent class, it is replaced by the parent class.

The specific use of these two implementations is to see the actual situation of the project, need to implement, can not modify the implements, only the definition of interface needs to be specific implementation, or can be modified to extend good, with extends.

Remember Mr. Zhang's video that said: If you use extends and implements at the same time, extends must be placed before the Implements keyword. such as: Class A extends B implements C.

Further understanding will continue to improve in the future.

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.