What is the purpose of sealed method in C#?Using a
sealed keyword along with a method means that the method cannot be overridden
by the next level of derived classes. But there is a constraint while
using sealed method: sealed method should be part of a derived class and
the method must be an overridden method.
Here is an example demonstrating usage of sealed method: namespace
Application1 { 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
|