Help with your answer

Briefly explain about Interface, Abstract, Virtual, and Interface vs Abstract

=> asked by Jae Lee

Categories: C# interview  


<< back to questions


An interface is a contract between itself and any class that implements it. This contract states that any class that implements the interface will implement the interface's properties, methods and/or events. An interface contains no implementation, only the signature of the functionality the interface provides. An interface can contain signatures of methods, properties and events. An interface is a contract and promise


An abstract method has no implementation. Its implementation logic is provided instead by classes that derive from it. We use an abstract class to create a base template for derived classes. A C# abstract class contains abstract members which define what a subclass should contain. Implementation of abstract members takes place within the derived class. A subclass which derives from an abstract class and fails to implement abstract methods will fail to compile.


A member defined as virtual must be implemented in the base class, but may be optionally overriden in the derived class if difference behavior is required.

Interface vs Abstract

An abstract class is a class that can NOT be instantiated but that can contain code. You have to use an abstract class to have another class. But, with an interface, you can create a new object by instantiating an interface. The difference between an abstract and an interface is that an abstract class can have a default implementation of methods, so if you don't override them in a derived class, the abstract base class implementation is used. Interface can not have any implementation.

over 3 years ago, by Jae Lee

Sponsored Links