Definition of interface:
public interface usb{}
Keyword interface;
Implement interface:
public class Computor implements usb{}
Keyword to implement interface: implements ;
Example:
(Video tutorial recommendation:java video)
The methods in the interface are Abstract method, so public abstract can be omitted. All variables are constants and must be assigned values. The default public abstract final int a=0;
There can be multiple interfaces Inheritance, a class can implement multiple interfaces. The interface also has a function for decoupling. The interface is a special abstract class. All access modifiers between interfaces are public, and all methods are abstract methods. All variables are constants;
A class implements an interface and must implement all methods in the interface;
Example:
Recommended tutorial:Getting started with java development
The above is the detailed content of How to define an interface in java. For more information, please follow other related articles on the PHP Chinese website!