Interface is an important data type in the Java language. The keyword interface is usually used to define an interface.
The definition of an interface is very similar to the definition of a class, divided into interface declaration and interface body, for example:
interfacePrintable{finalintMAX=100;voidadd();floatsum(floatx,floaty);}
An interface contains an interface declaration and an interface body. Unlike a class, an interface uses the keyword interface to declare itself to be an interface. The format is as follows:
interface name
The interface body contains two parts: constant declaration and abstract method. There are only abstract methods in the interface body, no ordinary methods, and the access rights of all constants in the interface body must be public, and they are static constants, and the access rights of all abstract methods must be public.
For example:
interfacePrintable{publicfinalstaticintMAX=100;//Equivalent writing: intMAX=100;publicabstractvoidadd();//Equivalent writing: voidadd();publicabstractfloatsum(floatx,floaty);//Equivalent writing: floatsum(floatx,floaty); }
Note: The modifiers public, final, and static can be omitted.