Allow class to be inherited and prevent method from being over-ridden - C#.NET

How can you allow class to be inherited and prevent the method from being overridden?

- Declare the class as public and make the methods sealed.

- The method declaration with a sealed modifier is called as a sealed method.

- The same method must also include the override modifier.

- With the use of sealed modifier, a derived class is prevented from further overriding the method.

- The sealed modifier is used to prevent derivation from a class.

- An error occurs if a sealed class is specified as the base class of another class.

- A sealed class cannot be an abstract class.

- Sealed method enables you to allow classes to derive from your class and prevent them from overriding specific virtual methods or properties.

Example:
class A
{
   protected virtual void show()
   {
       //Statements
   }
}

class B : A
{
   sealed protected override void shoe()
   {
       //Statements
   }
}
What is an interface class? - C#.NET
C#.NET - What is an interface class? - An interface class is an abstract class with public abstract methods...
Difference between an interface and abstract class - C#.NET
C#.NET - Difference between an interface and abstract class - In the interface all methods must be abstract...
C#.NET localized application
C#.NET localized application - The System.Resources namespace contains classes and interfaces...
Post your comment