Abstract Method:
If an abstract method is defined in a class, then the class should
declare as an abstract class.
An abstract method should contain only method definition, should not
Contain the method body/implementation.
An abstract method must be over ride in the derived class.
Virtual Method:
- Virtual methods can be over ride in the derived class but not
mandatory.
- Virtual methods must have the method body/implementation along
with the definition.
Example:
public abstract class baseclass
{
public abstract decimal getarea(decimal Radius);
public virtual decimal interestpermonth(decimal amount)
{
return amount*12/100;
}
public virtual decimal totalamount(decimal Amount,decimal principleAmount)
{
return Amount + principleAmount;
}
}
public class derivedclass:baseclass
{
public override decimal getarea(decimal Radius)
{
return 2 * (22 / 7) * Radius;
}
public override decimal interestpermonth(decimal amount)
{
return amount * 14 / 100;
}
}