Sealed keyword
what is difference between sealed class and private class because both are not inherited.
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
VulpesRank #55 · 29.2K reputationPosted Jul 16, 2012, 2:23 AM EDT
It can be inherited from but only by other nested classes within the class in which the private class itself is nested (private classes can never be 'top level').
For example, this program compiles and runs fine, printing "Hello" twice to the Console:
In contrast a sealed class cannot be inherited from at all and can be either top level or nested.
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 16, 2012, 4:06 AM EDT
Please refer
http://forums.asp.net/t/1564250.aspx/1
http://www.dotnetfunda.com/forums/thread5643-main-advantage-of-private-class-and-sealed-classes.aspx
hope this will help you.
SenthilkumarRank #387 · 6.5K reputationPosted Jul 16, 2012, 10:31 PM EDT
when you define the class as private then it will not allow you to inherit. But when you define the class as sealed then it allows you to create the instance for that class but it restrict to inherit further in any class.
Sealed class can't be base class to any other class. when you define the private class also same. But sealed allows you to create the object.
VulpesRank #55 · 29.2K reputationPosted Jul 17, 2012, 1:10 AM EDT