+--------------+---+-------------------------+------------------+---------------------+
| Class Type | | Can inherit from others | Can be inherited | Can be instantiated |
|--------------|---|-------------------------+------------------+---------------------+
| normal | : | YES | YES | YES |
| abstract | : | YES | YES | NO |
| sealed | : | YES | NO | YES |
| static | : | NO | NO | NO |
+--------------+---+-------------------------+------------------+---------------------+
Sealed Class | Static Class
--------------------------|-------------------------
it can inherit From other | it cannot inherit From other
classes but cannot be | classes as well as cannot be
inherited | inherited
public class BaseClassDemo
{
}
//Note
//A static class can be used as a convenient container for sets of
//methods that just operate on input parameters and do not have to
//get or set any internal instance fields.
//The advantage of using a static class is that the compiler can
//check to make sure that no instance members are accidentally
//added. The compiler will guarantee that instances of this class
//cannot be created.
//Static class 'static type' cannot derive from type 'type'. Static
//classes must derive from object.
public static class StaticClassDemo : BaseClassDemo //Error
public static class StaticClassDemo
{
//Static class must have static members
public static void Ram()
{
throw new NotImplementedException();
}
}
//Sealed class can inherit from the base class.
public sealed class SealedClassDemo : BaseClassDemo
{
}
//We can't derive from sealed class.
public class derivedClass:SealedClassDemo //Error
public partial class RandomClass2
{
//we can't create instance of static class.
StaticClassDemo demo = new StaticClassDemo() //Error
}