
What
is the purpose of sealed method
|
namespace
Application1 {
class baseClass {
public virtual void sampleMethod() {
Console.WriteLine("Executing sampleMethod of baseClass");
}
}
class derivedClass:baseClass {
public sealed override void sampleMethod() {
Console.WriteLine("Executing sampleMethod of derivedClass");
}
}
class derivedClass2 : derivedClass {
public override void sampleMethod() {
Console.WriteLine("Executing sampleMethod of derivedClass2");
}
}
}
In this example, you try to override the sealed method sampleMethod of derivedClass in derivedClass2. This is not permissible and you will end up in the following error:
'Application1.derivedClass2.sampleMethod()': cannot override inherited member 'Application1.derivedClass.sampleMethod()' because it is sealed
_______________________________________________________________________
FREE Subscription
Subscribe
to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.
Note
: We never rent, trade, or sell my email lists to
anyone.
We assure that your privacy is respected
and protected.
Visit .NET Programming Tutorial Homepage
______________________________________________________