3. Sealed
• Sealed modifier prevents other classes from inheriting from it
sealed class A
{
}
//Gives an error, due to sealed class A
class B : A
{
}
4. Abstract classes
• Abstract class cannot be instantiated, and is frequently either partially
implemented, or not at all implemented
public abstract class Country
{
public string Name { get; set; }
public string Currency { get; set; }
public void PrintInformation()
{
Console.WriteLine(Name);
Console.WriteLine(Currency);
Console.WriteLine(this.GetFlagDescription());
}
public abstract string GetFlagDescription();
}
5. Interfaces
• An interface is not a class.
• An interface is defined as a syntactical contract that all the classes
inheriting the interface should follow.
public interface IAlcohol
{
double AlcoholByVolume { get; set; }
double GetMaximumAllowedWightForHuman();
}
6. Abstract Class versus Interface
Feature Interface Abstract class
Multiple inheritance YES NO
Default implementation NO YES
Access Modfiers
NO (Everything goes
public by default)
YES
Fields and Constants NO YES