C# 'sealeld'

2018. 10. 9. 04:47 from Language/C#

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"); } }






'Language > C#' 카테고리의 다른 글

public, private, protected, internal keyword  (0) 2018.10.24
async await 사용시 조심해야 할 점  (0) 2018.10.14
Object Oriented Robot Programming  (0) 2018.10.14
'await' keyword  (1) 2018.10.13
메타데이터란?  (0) 2018.09.22
Posted by 나무길 :