Interface (interface)
1. The interface Body contains the declaration of the constant (no variable) and the abstract method two parts. There is only an abstract method in the interface body, there is no ordinary method, and all the constant access rights in the interface body must be public, and it is a static constant (which allows the public, final, and static modifiers to be omitted). Access to all abstract methods must be public (allow omitting public abstract modifier)
2. If a non-abstract class implements an interface, the class must override all methods in the interface. It should be noted that because the method in the interface must be the Public,abstract method, the class will not only remove the abstract modifier, give the method body when overriding the interface method, and the access permission of the method must be obviously decorated with public (otherwise, the access rights are reduced. This is not allowed). The non-abstract class implementing the interface realizes the method in the interface, and gives the concrete behavior function of the method.
3. If a class declaration implements an interface, but does not override all methods in the interface, the class must be an abstract class, that is, the abstract class can either override the methods in the interface or directly own the methods in the interface.
4. Define the interface is, if the keyword interface preceded by the public keyword, it is said that such an interface is a public interface. The public interface can be implemented by any one class. If an interface is not public decorated, it is called a friendly interface, and the friendly interface can be implemented with the class of the interface in the same package.
Demo Interface printable{ publicstaticfinalint MAX =; equivalent notation: int MAX = +; Public Abstract void Add (); // equivalent notation: void Add (); Public Abstract float sum ( float x,float y);}
Java Interface Basics