Saturday, June 26, 2010

Interface VS Abstract Class


I tried to find out the difference between Inteface and Abstract class. I have described it blow

1. Methods
In Abstract Class, User can implement method. In Interface, We can't implement any method. (Method signature is not allowed into Interface)

public abstract class TestAbstract
{
public string strProperty { get; set; }

public abstract void abstractMethod();

public string NormalMethod()
{
return "def";
}

}

public interface ITestInterface
{
string stringProperty { get; set; }

void abstractMethod();

}


In above code, NormalMethod is implemented into Abstract class but Interface is not allowed to implement method.

2. Access specifier
We can specify access specifier for property, method. But we cannot specify access specifier in Interface

3. Inheritance
Interface allows multiple inheritance but Abstract class is not allow multiple inheritance.

No comments:

Post a Comment

DotNet Code Guru