| |
|
How to inherit the class, but not the method inside it in C#? What is a sealed method in C#? Can
a method in C# be sealed? How to create a sealed method in C#?
If a method is not to be inherited, but the class is, then the method is sealed.
It becomes a sealed method of a class. It is important to note here that
in C#, a method may not be implicitly declared as sealed. This means that a method
cannot be sealed directly. A method in C# can be sealed only when the method is an overriden method.
Once the overriden method is declared as sealed, it will not be further overriding of this method.
See code sample below, where an overriden method is sealed.
C# Example
class SomeClass
{
public int a;
public int b;
public virtual void SomeMethod()
{
Console.WriteLine("This is a virtual method");
}
}
class SomeClass : DerivedClass
{
public override sealed void SomeMethod()
{
Console.WriteLine("This is a sealed method");
}
}
To know what is a sealed class in C#Click Here
Protected Internal
Array
Sort Array
Throw
Multiple Catch
Polymorphism
Inheritance
Session Viewstate
Autogenerate
ReadOnly
Sealed Class
Sealed Method
Multiple Interfaces
Overloading
Overloaded Constructors
Generics
Main
Case Sensitive
Console
Specifier
Return Type
SetCommandLineArgs
System Environment
New
Default Values of Types
Compiler Error
Constant Variable
Const
Const - ReadOnly
Parameter Modifier
Out Ref
Interface
Interface Reference, is, as
System.Collection
More Interview Questions...
| |