Posts

Showing posts with the label differencebetween

Difference between Abstract class and Interface

Abstract class. An abstract class in C# is a class which cannot be instantiated.   It is declared with abstract modifier. Generally abstract class is used to provide common definition or behavior that the derived classes can implement. For example public abstract class Employee { } Interface An interface in C# is just like a contract that other classes have to follow. It is declared with interface modifier. Interface is used to provide loose coupling between classes and its dependancies. For example interface IEmployee { } The difference between abstract class and the interface is as follows. Abstract Class Interface Abstract class is declared with abstract modifier An interface is declared with interface modifier It contains abstract as well as non-abstract methods It contains only abstract methods You can declare and define the methods in abstract class You can only d...