Java interface (interface), literacy stickers

Source: Internet
Author: User
Tags define abstract

Interface (interface) is another important technique provided by Java, which is very similar in structure to abstract classes and has data members and abstract methods, but it differs from the abstract class in the following two points:
1, the data members in the interface must be initialized, and the data members are constants.
2. The methods in the interface must all be declared abstract, that is, the interface cannot retain the general method as the abstract class, but must be all "abstract methods".

The syntax for the interface definition is as follows:

Interface interface name//define abstract class {     final data type  member name = constant  ;//data member must be assigned initial value    abstract returns the data type  method name (Parameters ... );    

An interface, like a generic class, has its own data members and methods, but the data member must be assigned an initial value, and it cannot be changed, and the method must also be an "abstract method". It is also because the method must be an abstract method, and there is no general method, so the abstract method declares the keyword abstractly can be omitted. The same situation also occurs with the data member, because the data member must be assigned an initial value, and it can no longer be changed, so the keyword final of the declaring data member can also be omitted.
The interface in Java is a mechanism for implementing multiple inheritance and is one of the most important aspects of Java design, and each class implemented by an interface must be an abstract method within the replication interface of the class and be free to use the constants in the interface. Since there is only abstract method in the interface, it only declares and does not define the processing mode, so it can naturally associate with the interface and has no way to create objects like the General class. The process of using an interface to create a new class is called an implementation of an interface (implementation).

Java interface (interface), literacy stickers

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.