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?
Loading
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.
Jignesh TrivediPosted Jan 25, 2012, 2:15 AM
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();
}
}
VulpesPosted Jan 24, 2012, 11:09 AM
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'.