An interface is a special abstract class, which is usually used by inheritance.
Why design abstract classes? For inheritance, common classes can also be used for inheritance. However, in reality, there are some classes that do not make sense to instantiate them. For example, animal, we do not instantiate an animal object, but instantiate a specific animal object such as bird and tiger. In this way, some methods can be declared in the class and are not implemented, this method is an abstract method.
Abstract classes can have common methods. abstract classes can have no abstract methods. However, classes with abstract methods must be abstract classes.
This shows the role of abstract classes:
1 is used to include some non-implementation methods.
2. It is used to determine the role of this class (can it be instantiated)
3. After inheritance, the abstract method must be rewritten.
The more pure abstract classes are interfaces, indicating that they all look like this and have the following features:
1. Full abstract class without any implementation
2 can be used for multi-Inheritance
3 contains attributes and is automatically static final.
4. The method is automatically public.
5. It is used for full decoupling, such as for policy mode and factory.