The code below will not compile and will have have the following error:
'SealedExample.SealedErrorClass': cannot derive from sealed type 'SealedExample.ExampleClass'
Sealed Class Example
namespace SealedExample
{
sealed class ExampleClass
{
public void MethodToInherit()
{
Console.WriteLine("This class is sealed so you can't inherit this method");
Console.WriteLine("Even though the method is public");
}
}
class SealedErrorClass : ExampleClass
{
//This does not work because ExampleClass is sealed
}
}
Additional Resources
Using Sealed Classes in .NET (C# Corner)
Sealed Keyword (Microsoft)
No comments:
Post a Comment