Abstract Class Vs Interface in C#.Net

By | December 10, 2017

Abstract Class Vs Interface in C#.Net

Abstract Class Vs Interface in C#.Net
Memebers Allowed Abstract as well as non abstact allowed. Only abstract members are Allowed.
Implementation of methods in derived classes Not necessary to implement all the methods of base (abstract) class for derived classes. The derived class must implement all the methods of interface.
Fields Can be defined. Can not be defined.
Access Modifier Can contain access modifiers for the functions, properties. Cannot have access modifiers for the functions, properties all members of interface is assumed as public.
Advantage of Interface over Abstract class A class may inherit only one abstract class. A class may inherit several interfaces.
Advantage of Abstract class over Interface Abstract classes can add more functionality without destroying the child classes that were using the old version. In an interface, creation of additional functions will have an effect on its child classes, due to the necessary implementation of interface methods to classes.

Now explanation of above points as below,

Members Allowed & Fields

Abstract class with abstract as well as non-abstract members as below,

Abstract Class Vs Interface in C#.Net

Abstract Class Vs Interface in C#.Net

Interface allows only abstract members (i.e. methods with declaration only not implementation) as below,

Abstract Class Vs Interface in C#.Net

Abstract Class Vs Interface in C#.Net

Access Modifier and Implementation of methods in derived classes

 

c# interview questions

Leave a Reply

Your email address will not be published. Required fields are marked *