Hello Sir...........
Why are you used sealed class in c# and which condition we can apply sealed class?
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
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 4, 2014, 10:23 PM EDT
hi,
Sealed classes are used to restrict the inheritance feature of object oriented programming. Once a class is defined as a sealed class, the class cannot be inherited.
public sealed class A
{
// Class members here.
}
public class B : A
{
}
above code is give compilation error.
refer
http://msdn.microsoft.com/en-IN/library/ms173150.aspx
hope this will help you.
Princy GuptaRank #1,602 · 982 reputationPosted Jun 4, 2014, 10:24 PM EDT
good article:
http://www.codeproject.com/Articles/239939/Csharp-Tweaks-Why-to-use-the-sealed-keyword-on-cla
Abhishek KumarRank #510 · 4.8K reputationPosted Jun 4, 2014, 11:17 PM EDT
When applied to a class, the sealed modifier prevents other classes from inheriting from it. Sealed classes are used to restrict the inheritance feature of object oriented programming. Once a class is defined as a sealed class, the class cannot be inherited.
Using sealed keyword will make class sealed and restricted as below.
sealed class SealedClass
{
}
A sealed class cannot be used as a base class. For this reason, it cannot also be an abstract class. Sealed classes are primarily used to prevent derivation.
Sealed class should be mainly used for security purpose.
Hope this makes sense to you. Many Thanks.
Lakshmanan Sethu SankaranarayanRank #124 · 17.7K reputationPosted Jun 4, 2014, 11:19 PM EDT
Please check this
http://www.c-sharpcorner.com/UploadFile/mahesh/SealedClasses11142005063733AM/SealedClasses.aspx
Anupam SinghRank #643 · 3.7K reputationPosted Jun 4, 2014, 11:43 PM EDT
In short sealed class can not have any child or derived class.
In .NET
for example in .NET framework, String is a sealed class .
Shweta LodhaRank #31 · 39.8K reputationPosted Jun 5, 2014, 11:08 PM EDT
Keyur PatelRank #1,216 · 1.5K reputationPosted Jun 6, 2014, 4:50 AM EDT
It's good explanation about the sealed class in microsoft site.
http://msdn.microsoft.com/en-us/library/88c54tsw.aspx