When we create a sealed class then we cannot inherit that class with any derived class. It is created when we want to restrict the class from being inherited. if we use a shield class with any derived class then the compiler will throw an error. We can use the property of a sealed class in any other class by creating an object.
Code:- using System
class Class1
{
static void Main(string[] args)
{
SealedClass sealedCls = new SealedClass();
int total = sealedCls.Add(4, 5);
Console.WriteLine("Total = " + total.ToString());
}
}
sealed class SealedClass
{
public int Add(int x, int y)
{
return x + y;
}
}
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
When we create a sealed class then we cannot inherit that class with any derived class. It is created when we want to restrict the class from being inherited. if we use a shield class with any derived class then the compiler will throw an error. We can use the property of a sealed class in any other class by creating an object.