Interface Implementation and Inheritance in Java Collections

Many people are confused about interfaces and abstract implementation classes. Pay attention to the difference between implementing interfaces and inheritance. The dark colors in the figure are interfaces, the light colors are implementation classes, extend is inheritance, and implements is interface implementation.

 

List and Set interfaces inherit from Collection interface

LinkedList is inherited from AbstractSequentialList (abstract class that implements the List interface)

ArrayList and Vector are inherited from AbstractList (abstract class that implements the List interface)

AbstractSet implements the Set interface and is itself an abstract class. Inherited from AbstractCollection (abstract class, implements the Collection interface)

HashSet is inherited from AbstractSet and implements the Set interface

Linked HashSet inherits HashSet and implements the Set interface

 

 

The difference between implementing an interface and inheriting is that

Class B implements interface A , that is, class B implements all the methods defined in interface A; none of the methods defined in interface A can be missing in class B, and must be implemented concretely.
The X class inherits the Y class, and the X class can directly use the methods in the Y class (there is no need to implement the methods in the Y class, the methods have already been implemented, of course, the abstract class is an exception)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324893495&siteId=291194637