Language/C#
C# 'sealeld'
나무길
2018. 10. 9. 04:47
Sealed concept
When applied to a class, the 'sealed' modifier prevent other classes from inheriting from it.
sealed Example
In the Following example, Z inherits from Y but Z cannot override the virtual function F that is declared in X and sealed in Y.
class X { protected virtual void F() { Console.WriteLine("X.F"); } protected virtual void F2() { Console.WriteLine("X.F2"); } } class Y : X { sealed protected override void F() { Console.WriteLine("Y.F"); } protected override void F2() { Console.WriteLine("Y.F2"); } } class Z : Y { // Attempting to override F causes compiler error CS0239. // protected override void F() { Console.WriteLine("Z.F"); } // Overriding F2 is allowed. protected override void F2() { Console.WriteLine("Z.F2"); } }