Java interface, interface, class, abstract class difference, java Abstract
1. Definition
Java interfaces are a series of methods declarations and a set of methods features. An interface has only the features of a method and is not implemented by a method. Therefore, these methods can be implemented by different classes in different places, these implementations can have different behaviors (functions ).
2. Differences between Java interfaces and interfaces
Java interface, the structure in the Java language, with specific syntax and structure.
package jiekou;public interface AreaInterface{double pai=Math.PI;double area();}The above program is a Java interface, which is a structure;
Interface, a feature set of methods of a class, is a logical abstraction.
The interface refers to the double area (); function.
3. Differences between Java interfaces and Classes
Interface implementation is different from the rule of class inheritance. for data security, when a class is inherited, there is only one direct parent class, that is, single inheritance. However, a class can implement multiple interfaces, interfaces make up for the inability to inherit more classes. The dual Design of inheritance and interfaces not only ensures the data security of classes, but also achieves multi-inheritance in disguise. Java interfaces do not have any implementations, Because Java interfaces do not involve representations and only describe public behaviors. Therefore, Java interfaces are more abstract than Java Abstract classes. However, an interface is not a class and cannot be instantiated using the new operator. For example, x = new comparable (...); // This is incorrect. However, you can declare the interface variable Comparable x; // This is allowed. Java interface methods can only be abstract and public. Java interfaces cannot have constructors. Java interfaces can have public, static, and final attributes. That is, the attribute in the interface can be defined as public static final int value = 5;