Difference between abstract class and interface

  1. Neither abstract classes nor interfaces can be instantiated, but references to abstract classes and interface types can be defined
  2. If a class inherits an abstract class or implements an interface, it must override all abstract methods, otherwise it must declare the class as an abstract class
  3. Abstract classes have constructors, interfaces do not have constructors, and the constructors of abstract classes can be called by subclasses using the super keyword
  4. The members in the abstract class can be public, private, default, protected, while the members in the interface are public
  5. The methods in the interface are abstract, the abstract class does not necessarily have abstract methods, the class with abstract methods must be abstract classes

Guess you like

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