Hi, Sealed keyword is used to prevent derivation from a class. That means you will get an error if you specify sealed class as the base class of another class. It wont be declared as abstract also. Basically, a sealed class is known to never have any derived classes.
That is why you won't be able to derive anything from structs as they are sealed. Take a Example code as below:
Code:
using System;
sealed class Testing
{
public int a;
public int b;
}
class Maintest
{
public static void Main()
{
Testing tt = new Testing();
tt.a = 110;
tt.b = 150;
Console.WriteLine("a = {0}, b = {1}", tt.a, tt.b);
}
}
In the preceding example, if you attempt to inherit from the sealed class by using a statement like this:
Code:
class DerivedTesting: Testing {} // Error will be thrown
You will get the error message such as :
'DerivedTesting' cannot inherit from sealed class 'Testing'.
Bookmarks