What are sealed classes in C# dotnet
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Jun 29, 2025, 2:27 PM EDT
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/
Sangeetha SRank #212 · 11.4K reputationPosted Jul 2, 2025, 7:00 AM EDT
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'
}