1. Definition
Java interface is the declaration of a series of methods, is a collection of methods features, an interface only the methods of the characteristics of the method is not implemented, so these methods can be implemented in different places by different classes, and these implementations can have different behavior (function).
2, Java interface and interface differences
Java interface, The structure that exists in the Java language has a specific syntax and structure.
Package Jiekou;public Interface areainterface{double pai=math.pi;double area ();
The above program is the Java interface, is a structure;
Interface, a collection of features of the methods that a class has, is a logical abstraction.
The interface refers to a double area () function.
3. The difference between Java interface and class
Interface implementation and class inheritance rules, in order to secure the data, the inheritance of a class only a direct parent class, that is, single inheritance, but a class can implement multiple interfaces, the interface to compensate for the class cannot inherit the disadvantage, inheritance and interface of the dual design both maintain the class of data security also disguised implementation of multiple inheritance. The Java interface itself has no implementation, because the Java interface does not involve appearances, but only describes the public behavior, so the Java interface is more abstract than the Java abstract class. But the interface is not a class, and you cannot instantiate an interface with the new operator. such as x=new comparable (... );//This is a mistake. However, the interface variable comparable x can be declared; This is permissible.Java interface methods can only be abstract and public, the Java interface cannot haveConstructors, the Java interface can have public,Staticand final properties. That is, the properties in the interface can be defined as public static final int value=5;
The differences between Java interfaces, interfaces, classes, and abstract classes