Hi...
Ques : Hello friend I have some confusion related to inheritance please explain How to allowed a class to be inherited, but it must be prevent the method from being over-ridden?
How to allowed a class to be inherited
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


VulpesRank #55 · 29.2K reputationPosted Jan 24, 2012, 6:09 AM EST
public sealed class MyClass // can't inherit from this class
{
// code
}
If a child class contains a method which overrides a virtual method in its base class, you can prevent further overriding by descendants of the child class by marking the method as 'sealed'.
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 24, 2012, 9:15 PM EST
try.... method it self sealed.
public class test1
{
public sealed void notoverride()
{
}
public virtual void fnoverride()
{
}
}
public class test2 : test1
{
public override void fnoverride()
{
base.fnoverride();
}
}