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