Preface
At first glance, the functions implemented by the two seem to be similar, because neither can be instantiated, but in fact the difference is still very big
the difference
-
Abstract classes must be inherited
by subclasses, interfaces must be implemented by classes
-
Interface can only do method declarations
abstract class can be used as a method declaration , you can do way to achieve
-
Variables defined in interfaces can only be public static constants
Variables in abstract classes are ordinary variables
-
Interfaces are the result of design.
Abstract classes are the result of refactoring .To put it in a bit easier to understand here, it is:
interface , which is to write all the subtitles before writing the article. Then everyone uses the same subtitles, but the following articles can be free to use the
abstract category , that is, write all the subtitles before writing the article, but you can also write some articles in advance under the subtitles. Then when others use these titles, they can use those articles directly, or they can rewrite their own articles instead of those articles.
-
Abstract classes and interfaces are used to abstract concrete objects, but the abstraction level of the interface is the highest
-
Abstract classes can have concrete methods and attributes.
Interfaces can only have abstract methods and immutable constants.
7. Abstract classes are mainly used to abstract categories. The
interface is mainly used to abstract functions.
This shows the essence! ! !