【Foreword】 |
There are connections and differences between arrays, collections, and generics. What is the difference between interfaces and abstract classes? Let’s talk about it.
【content】 |
Arrays, collections, generic collections
~ | array | gather | Generic collection |
---|---|---|---|
the difference | control length, control type | No control of length, no control of type | Does not control the length, controls the type |
definition | int[ ]i=new int (5); | Array List arr=new Array List(); array list needs to click on the light bulb example using stystem.collections; | list i list=new list(); |
For some specific differences, please refer to: For
detailed differences, please click! !
Interfaces and abstract classes:
~ | interface | abstract class |
---|---|---|
concept | An interface is an abstraction of an action | An abstract class is an abstraction of the root |
describe | The interface represents what the object can do | The abstract class represents what this object is |
When you focus on the essence of a thing, use abstract classes; when you focus on an operation, use interfaces.
Abstract classes are much more functional than interfaces, but the cost of defining abstract classes is high. Because high-level languages say each class intelligently integrates a class, in this class, you must inherit or write all the commonalities of all its subclasses. Although the interface is functionally weak, it is only a description of an action, and you can have multiple interfaces in a class at the same time.
【Summarize】 |
Abstract classes and interfaces will often appear in the programming process. I hope you will learn more about them. If you have any additions, please submit them.