1. Definition of interface:
public interface usb{}
Keyword interface;
Implementation interface: public class Computor implements usb{}
Keywords for implementing the interface: implements;
2. The methods in the interface are all abstract methods, so public abstract can be omitted If not written, all variables are constants and must be assigned values. The default is public abstract final int a=0;
3. Interfaces can have multiple inheritances and can be implemented in one class Those multiple interfaces, the interface also has a function for decoupling. The interface is a special abstract class. All access modifiers between interfaces are public, all methods are abstract methods, and all variables are constants. ;
4. A class implements an interface and must implement all methods in the interface;
Recommended tutorial :JavaTutorial
The above is the detailed content of How to define interface in java. For more information, please follow other related articles on the PHP Chinese website!