The difference between abstract classes and interfaces and links

  • interface

  (1) the interface can not be instantiated 
  (2) comprising an interface method declarations can
  member (3) comprises interface methods, properties, indexers, events
  (4) the interface can not contain constants, fields (fields), a constructor, analysis configuration, static member
  all members (5) the default interface to public, and therefore the interface can not have a private modifier
  all members (6) of the derived classes must implement the interface
  (7) a class can directly implement multiple interfaces, the interfaces Room separated by commas
  (8) can have a plurality of interfaces parent interface, implements the interface must implement all the members of all interfaces in the parent
  •  Abstract class

  (1) only for the abstract method declarations, but not comprising achieved, can be seen as a virtual method is not achieved body 
  (2) can not be instantiated abstract class
  (3) may, but need abstract class abstract abstract methods and properties, but Once you have abstract methods, we must take this abstract class declaration of
  (4) particular abstract derived class must override base class methods
  (5) abstract derived class can override an abstract base class, may not be covered. If you do not cover, its concrete derived classes must override them.
  •  Same point

  (1) it can be inherited 
  (2) not be instantiated
  (3) may comprise a method declared
  method is not implemented (4) derived class must implement
  •  the difference

   1. Interface specifies what you can do, and abstract class defines what you are.

   2. ① aircraft can fly, birds fly, they have inherited the same interface "fly"; but F22 aircraft belonging to an abstract class, abstract class pigeons belong to the birds.

    ② like iron gate doors are doors (abstract class), you want a door I can not give (can not be instantiated), but I can give you a specific gates or doors (multi-state); and only at the door you can not say that it is a window (single inheritance); a door can be locked (interfaces) can also doorbell (more than realized). Door (abstract class) defines what you are, an interface (lock) sets out what you can do (the best one interface can only do one thing, you can not ask locks can sound bar (Interface pollution)).

 

  

Guess you like

Origin www.cnblogs.com/qwfy-y/p/11792539.html