The difference between abstract class and interface

xiaoxiao2021-03-06  15

1. Abstract classes can contain partial methods, which is a major place in an abstract class than the interface.

2. Since Java's single inheritance, each class can only inherit from one abstraction, but each class can implement multiple interfaces, using the interface, you can implement the Mixin mixed type class.

3. Extracting the generic part as an interface is easy, and it is not convenient as an abstract class because this class may have inherited from another class.

4, you can use the interface and abstraction class. In the collection framework system, the top-level interface Collection defines some methods while providing several abstract class AbstractCollection, AbstractList, Abstractmap implementation, so that the specific collection implementation class can choose from the abstraction class or directly implement the interface.

转载请注明原文地址:https://www.9cbs.com/read-46962.html

New Post(0)