Tag Archives: Abstract Class

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#

Abstract Class FACTS

Abstract Class FACTS

1) We can inherit abstract class from another abstract class also.

Eg:

public abstract class AbstractClass1

{
public abstract string TestMe();       

}

 It is inherited by AbstractClass2 

public abstract class AbstractClass2 : AbstractClass1

{
public abstract string DoSome();

public override string TestMe()

{

return “This is test”;

}

}

2) Abstract class can inherit Interface also.

Leave a comment

Filed under .Net, C#