OOPS


Difference between Abstract class and Interface in C# .Net

Interfaces are essentially having all method prototypes no definition but Abstract class can contain method definations also.

In short Interface is a abstract class having all methods abstract.

If you create a abstract class writing the abstract keyword in the declaration part then You only can inherit the class. You can not create an instance of this abstract class but can inherit the class and with creating the instance of the derived class you can access the method of the abstract class.

If you use a virtual keyword in a method then you can override this method in the subclass if you wish..

If you create a abstract method then you must override this method in the subclass other wise it shows error in the program.

You cannot instantiate Abstract Classes and Interfaces

An interface has all public members

 You can inherit abstract classes to other class

Abstract :
=========================================
1. Abstract class cannot be instantiated.
2. Abstract class may contain abstract methods and accessors.
3. Abstract modifier can be used with classes, methods and properties.
4. A non-abstract class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors.
5. Abstract method declarations are only permitted in abstract classes.
6.Abstract class can contain abstract methods, abstract property as well as other members (just like normal class).
7.Interface can be used to achieve multiple inheritance; abstract class can be used as a single inheritance
8.Abstract class are known as partial abstract class whereas interface is known as fully abstract class
***********************************************************
Interface :
=========================================
1.Interfaces are similar to classes.
2.They can have member properties and methods.
3.All the properties and methods of interfaces are abstract.
4.They have no body, just the declaration.
5.Public, Protected, Private, Friend, Shared, Overrides, MustOverride, NotOverridable are permitted inside an interface.

6.It’s a pure abstract class.



0 comments: