sealed
suggest changeWhen applied to a class, the sealed
modifier prevents other classes from inheriting from it.
class A { }
sealed class B : A { }
class C : B { } //error : Cannot derive from the sealed class
When applied to a virtual
method (or virtual property), the sealed
modifier prevents this method (property) from being overriden in derived classes.
public class A
{
public sealed override string ToString() // Virtual method inherited from class Object
{
return "Do not override me!";
}
}
public class B: A
{
public override string ToString() // Compile time error
{
return "An attempt to override";
}
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents