Thursday 2 February 2012

Difference between Interface and Abstract Class


Difference between Interface and Abstract Class
  • Interfaces are closely related to abstract classes that have all members abstract.
  • For an abstract class, at least one method of the class must be an abstract method that means it may have concrete methods.
  •  For an interface, all the methods must be abstract
  • Class that implements an interface much provide concrete implementation of all the methods definition in an interface or else must be declare an abstract class
  • In C#, multiple inheritance is possible only through implementation of multiple interfaces. Abstract class can only be derived once.
  • An interface defines a contract and can only contains four entities viz methods, properties, events and indexes. An interface thus cannot contain constants, fields, operators, constructors, destructors, static constructors, or types.
  • Also an interface cannot contain static members of any kind. The modifiers abstract, public, protected, internal, private, virtual, override is disallowed, as they make no sense in this context.
  • Class members that implement the interface members must be publicly accessible.

No comments:

Post a Comment