The difference between abstract class and interface

Please indicate the source for the original reprint: http://agilestyle.iteye.com/blog/2392437

 

abstract class

  • It consists of abstract methods and constants, variables, global constants, constructors, and ordinary methods
  • Use abstract statement
  • Subclasses must inherit abstract classes through extends. If subclasses are not abstract classes, they must override all abstract methods in the abstract class.
  • There is a single inheritance limitation, a subclass can only inherit one abstract class
  • An abstract class can implement several interfaces

interface

  • All consist of abstract methods and global constants
  • use interface declaration
  • The subclass implements the interface through implements. If the subclass is not an abstract class, it must override all abstract methods in the abstract class
  • There is no single inheritance limitation, a subclass can implement multiple interfaces at the same time
  • An interface cannot inherit an abstract class, but multiple interfaces are allowed to inherit

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326866045&siteId=291194637