What are sealed classes in C# dotnet
Loading
What are sealed classes in C# dotnet
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sangeetha SPosted Jul 2, 2025, 11:00 AM
In C# (.NET), a sealed class is a class that cannot be inherited. This means no other class can derive from a sealed class. You use the
sealedkeyword to declare such a class.sealed class FinalLogger
{
public void Log(string message)
{
Console.WriteLine($"Log: {message}");
}
}
// This will cause a compile-time error
class CustomLogger : FinalLogger
{
// Error: cannot derive from sealed type 'FinalLogger'
}
Rajanikant HawaldarPosted Jun 29, 2025, 6:27 PM
Class that cannot be inherited by other classes is called sealed class. Purpose is restrict inheritance.
https://www.c-sharpcorner.com/article/sealed-class-in-C-Sharp/