Hi..
here is the link to give brief difference
http://www.dotnetbull.com/2011/11/difference-between-abstract-class-and.html[
^]
Abstract class:
a) An abstract class is a special kind of class that cannot be instantiated.
b) It allows the other classes to inherit from it but cannot be instantiated.
c) It is used to carry the same hierarchy or standards for all the subclasses.
d) A class can inherit an abstract class without implementing all its abstract method.
However only a class that has all its method implemented can be instantiated to an object.
IS-A relationship.
e.g. Student IS A Person, Employee IS A Person.
example
public abstract Person
{
public abstract SendPaperWork(string paperwork)
public void Enrol()
{
SendPaperWork("enrolment");
}
public void Submit()
{
SendPaperWork("report");
}
}
public class Student : Person
{
public override SendPaperWork(string paperwork)
{
School.Send(paperwork);
}
}
public class Employee : Person
{
public override SendPaperWork(string paperwork)
{
Company.Send(paperwork);
}
}
Interface:
a) An interface is not a class,but it is an entity and has no implementation.
b) It has only the definition of the methods without the body
c) A class that implements an Interface need to contain all the implementation, otherwise the compiler will throw an error.
CAN-DO relationship.
e.g. Student CAN enrol, Student CAN submit assignment.
example
public interface ICanEnrol
{
void Enrol();
}
public interface ICanSubmit
{
void Submit();
}
public class Student : ICanEnrol, ICanSubmit
{
public void Enrol()
{
School.Send("enrolment");
}
public void Submit()
{
School.Send("report");
}
}
public class Employee : ICanEnrol, ICanSubmit
{
public void Enrol()
{
Company.Send("enrolment");
}
public void Submit()
{
Company.Send("report");
}
}
public class MailServer
{
public void SendAllSubmissions()
{
foreach (ICanSubmit submitter in AllSubmitters)
{
submitter.Submit()
}
}
}
Thank You
Happy Coding