What is sealed class in C#?
In today's post i am going to cover "What is Sealed class in C# "?
Sealed is a keyword to declare a class as sealed.A class which can not be inherited is know as sealed class.
Sealed classes are used to restrict the inheritance feature of object oriented programming. Once a class is defined as sealed class, this class cannot be inherited. A sealed class cannot be used as a base class. For this reason, it cannot also be an abstract class. Sealed classes are primarily used to prevent derivation.
Below code will show how to declare sealed class.
Sealed Method
When an is decorated with a sealed modifier, that method is said to be a sealed method.A sealed method overrides an inherited virtual method with the same signature. A sealed method shall also be marked with the override modifier. Use of the sealed modifier prevents a derived class from further overriding the method.
Here is the example to explain the above sentences.
Below i have tired to show how sealed keyword is used to prevent a method to be further overloaded.
Hope you have enjoyed the post.Please provide your feedback.
Thanks.
What is sealed class in C#?
Reviewed by CodiBucket
on
06:10
Rating:
No comments: