Interface considerations: 1 , interfaces cannot be instantiated 2 , all methods in an interface cannot have a principal. Error syntax example: void aaa () {}← (note cannot have curly braces), interfaces can be considered abstract classes that are more abstract. 3 , a class can implement multiple interfaces, non-abstract class implementation interface must implement all the methods in the interface (abstract class facilitates code reuse, interface for code maintenance) 4 , the interface can be defined constants (int a=1;//plus no static are static, cannot be modified with private and protected), cannot define variables ★ There can be variables in the interface [but the variables cannot be modified with private and protected], the variables in the interface are essentially static and final type, whether you add static modifiers or not. Access form: interface name. variable name ★ In Java, the commonly used variables, defined in the interface, as a global variable use, the interface properties are automatically with public static final decoration, that is, the interface properties are global static variables; 5 , an interface cannot inherit other classes, but it can inherit other interfaces 6 , the interface name rule is the same as the class, public is visible throughout the project, and if omitted, it can only be visible in the current package; 7 , an important principle: When a class implements an interface that requires the class to implement all the methods of the interface, otherwise it must be defined as an abstract class; 8 , all the methods in the interface are abstract methods, and the methods in the interface automatically call the public abstract decoration, that is, only the global abstract method in the interface; 9 , and abstract classes, interfaces can not be instantiated, interfaces can not have a construction method; Ten , the interface can realize the inheritance relationship through extends, an interface can inherit multiple interfaces, but cannot inherit the class; |