The difference point between Java abstract classes and interfaces
1, the interface can only contain abstract methods, the abstract class can contain partial implementation methods.
2, the interface can only define static constants, the default is public static final, and need to display initialization. You can define normal member variables in an abstract class.
3, the interface can not contain the construction method, the abstract class may have its own construction method (inherited use).
4, interfaces and abstract classes cannot be instantiated.
5, a class can implement multiple interfaces, can only inherit an abstract class (can inherit only one class, single inheritance)
6, a class implementation of the interface needs to implement all methods. Inheriting an abstract class requires implementing all of the abstract methods, otherwise it needs to be declared as an abstract class. (If a class contains abstract methods, the class must be declared as abstract class)
7. If a new concrete method is added to an abstract class, all its subclasses are automatically given this new method. If you add a new method to an interface, all classes that implement the interface must be modified synchronously to implement this method, otherwise they cannot be compiled.
8, the implementation of the abstract class can only be given by its subclasses, and Java is a single inheritance, so the abstract class as a type definition tool performance is greatly compromised. Any class that implements an interface can have a type of this interface, and a class can implement multiple interfaces at the same time, so that the class has multiple types.
Java Learning (13): The difference between abstract classes and interfaces, their pros and cons