Interface interface:
1. There is no variable in the interface, the member is defined by any means, and public static final is the same even if it is not explicitly declared.
2. All interface methods imply public abstract even if they are not explicitly declared. (and therefore cannot use protected and private adornments, not modifiers or default permissions)
3. Interfaces can inherit other interfaces but cannot inherit classes, cannot design methods in parent interfaces, and cannot implement other interfaces.
4. Any class can reference an interface and implement its methods in a self-class implementation.
Abstract class:
1. Variables and methods can define permissions, just like normal classes.
2. An abstract class can have only one inherited parent class but can implement many interfaces as well as normal classes.
3. Subclasses can inherit the same abstract class as the normal class. In other words, abstract classes are just ordinary classes that can use abstract methods.
See here, believe that everyone is thinking, since the interface itself can not achieve any function and can only provide some constants, then what is the meaning of the interface?
I think the interface is more like the upper layer of the document, in the Java Web Middle-tier development, will often provide an interface-to implement such a development model, in the case of the interface class does not change, arbitrary changes in the implementation of the other layers have no effect, as long as the interface does not gerze other layers need not change, The interface acts more like an API document. This reduces the coupling of the application and enhances the scalability of the program.
When we need to check which interfaces our objects use, which classes we inherit, we can check with instanceof, instanceof looks like a function name, but it is actually an operator, and it is used in a similar way:
Son son=new son ();
if (son isntanceof Father) {
}
The symbol to the left is an object, the right is a class name, you can check whether there is an inheritance relationship and implement implementation relationship, Chinese translation can be: can be seen as.
Using this operator, we can better organize our inherited polymorphic structure, or we can use some polymorphic functions better.
The meaning of Java interfaces and abstract classes and interfaces