ABSTRACT vs INTERFACE

ABSTRACT vs INTERFACE

Abstract Class Interface
1. It is mainly used in versioning scenarios (defining core functionalities). Interface is used as contract mainly.
2. We can use abstract as well non-abstract method. All methods are abstract only. Interface is pure abstract class.
3. We can inherit only one abstract class at a time. We can implement multiple interface.
4. All access modifier can be used. We can have only public access modifier for the methods.

à We can not create object of abstract class, though abstract can have constructors.

àWe can create instance of abstract class like:

AbstractClass obj = new SubClass();

eg:

TextWriter abstract class have two sub classes i.e. StreamWriter & StringWriter

TextWriter tObj = new StreamWriter();

Advertisements

Leave a comment

Filed under C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s